diff --git a/app/Http/Controllers/RecipeStepController.php b/app/Http/Controllers/RecipeStepController.php new file mode 100644 index 0000000..717b5de --- /dev/null +++ b/app/Http/Controllers/RecipeStepController.php @@ -0,0 +1,85 @@ +hasMany(RecipeStep::class)->orderBy('number'); + } /** * Get the Ingredient Amounts used for this Recipe. */ public function ingredientAmounts(): HasMany { - return $this->hasMany(IngredientAmount::class); + return $this->hasMany(IngredientAmount::class)->orderBy('weight'); } /** diff --git a/app/Models/RecipeStep.php b/app/Models/RecipeStep.php new file mode 100644 index 0000000..c5ee4de --- /dev/null +++ b/app/Models/RecipeStep.php @@ -0,0 +1,33 @@ +belongsTo(Recipe::class); + } +} diff --git a/database/factories/RecipeStepFactory.php b/database/factories/RecipeStepFactory.php new file mode 100644 index 0000000..76d98e9 --- /dev/null +++ b/database/factories/RecipeStepFactory.php @@ -0,0 +1,28 @@ +id(); $table->string('name'); + $table->longText('description'); + $table->unsignedInteger('servings'); $table->timestamps(); }); } diff --git a/database/migrations/2020_12_22_051133_create_recipe_steps_table.php b/database/migrations/2020_12_22_051133_create_recipe_steps_table.php new file mode 100644 index 0000000..ef2ee08 --- /dev/null +++ b/database/migrations/2020_12_22_051133_create_recipe_steps_table.php @@ -0,0 +1,35 @@ +id(); + $table->foreignIdFor(Recipe::class); + $table->unsignedInteger('number'); + $table->longText('step'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('recipe_steps'); + } +} diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php index eab3cc3..57e9884 100644 --- a/database/seeders/RecipeSeeder.php +++ b/database/seeders/RecipeSeeder.php @@ -5,6 +5,7 @@ namespace Database\Seeders; use App\Models\Ingredient; use App\Models\IngredientAmount; use App\Models\Recipe; +use App\Models\RecipeStep; use Illuminate\Database\Seeder; class RecipeSeeder extends Seeder @@ -15,7 +16,11 @@ class RecipeSeeder extends Seeder public function run(): void { /** @var \App\Models\Recipe $recipe */ - $recipe = Recipe::factory()->create(['name' => 'pancakes']); + $recipe = Recipe::factory()->create([ + 'name' => 'pancakes', + 'description' => 'Basic pancakes in two steps.', + 'servings' => 4, + ]); $weight = 0; $amounts = [ @@ -76,5 +81,19 @@ class RecipeSeeder extends Seeder ], ]; IngredientAmount::factory()->createMany($amounts); + + $steps = [ + [ + 'recipe_id' => $recipe->id, + 'number' => 1, + 'step' => 'In a large bowl, mix flour, sugar, baking powder and salt. Make a well in the center, and pour in milk, egg and oil. Mix until smooth.', + ], + [ + 'recipe_id' => $recipe->id, + 'number' => 2, + 'step' => 'Heat a lightly oiled griddle or frying pan over medium high heat. Pour or scoop the batter onto the griddle, using approximately 1/4 cup for each pancake. Brown on both sides and serve hot.', + ] + ]; + RecipeStep::factory()->createMany($steps); } }