diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php new file mode 100644 index 0000000..1e90ea2 --- /dev/null +++ b/app/Http/Controllers/RecipeController.php @@ -0,0 +1,85 @@ +hasOne(Ingredient::class); + public function ingredient(): BelongsTo { + return $this->belongsTo(Ingredient::class); + } + + /** + * Get the Recipe this amount belongs to. + */ + public function recipe(): BelongsTo { + return $this->belongsTo(Recipe::class); } } diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php new file mode 100644 index 0000000..3416da7 --- /dev/null +++ b/app/Models/Recipe.php @@ -0,0 +1,27 @@ +hasMany(IngredientAmount::class); + } +} diff --git a/database/factories/RecipeFactory.php b/database/factories/RecipeFactory.php new file mode 100644 index 0000000..5a5eac9 --- /dev/null +++ b/database/factories/RecipeFactory.php @@ -0,0 +1,28 @@ +id(); - $table->unsignedFloat('amount'); $table->foreignIdFor(Ingredient::class); + $table->unsignedFloat('amount'); + $table->foreignIdFor(Recipe::class); + $table->unsignedInteger('weight'); $table->timestamps(); }); } diff --git a/database/migrations/2020_12_21_215932_create_recipes_table.php b/database/migrations/2020_12_21_215932_create_recipes_table.php new file mode 100644 index 0000000..cd4c97f --- /dev/null +++ b/database/migrations/2020_12_21_215932_create_recipes_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('recipes'); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index bae579c..8a915b0 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -8,11 +8,10 @@ class DatabaseSeeder extends Seeder { /** * Seed the application's database. - * - * @return void */ - public function run() + public function run(): void { $this->call(IngredientSeeder::class); + $this->call(RecipeSeeder::class); } } diff --git a/database/seeders/IngredientAmountSeeder.php b/database/seeders/IngredientAmountSeeder.php deleted file mode 100644 index 816a514..0000000 --- a/database/seeders/IngredientAmountSeeder.php +++ /dev/null @@ -1,18 +0,0 @@ - 'black beans', - 'unit' => 'cup', - 'calories' => 236, - 'protein' => 15.9, - 'fat' => 0.972, - 'carbohydrates' => 42.3 + 'name' => 'baking powder', + 'unit' => 'tsp', + 'calories' => 2.44, + 'protein' => 0, + 'fat' => 0, + 'carbohydrates' => 1.27 ], [ - 'name' => 'egg white', - 'calories' => 17.2, - 'protein' => 3.6, - 'fat' => 0.056, - 'carbohydrates' => 0.241 + 'name' => 'egg', + 'calories' => 71.5, + 'protein' => 6.28, + 'fat' => 4.76, + 'carbohydrates' => 0.36 + ], + [ + 'name' => 'flour, all-purpose', + 'unit' => 'cup', + 'calories' => 455, + 'protein' => 12.9, + 'fat' => 1.22, + 'carbohydrates' => 95.4 ], [ 'name' => 'milk, whole', @@ -39,12 +45,28 @@ class IngredientSeeder extends Seeder 'carbohydrates' => 11.4 ], [ - 'name' => 'rice, brown (cooked)', + 'name' => 'salt', + 'unit' => 'tsp', + 'calories' => 0, + 'protein' => 0, + 'fat' => 0, + 'carbohydrates' => 0 + ], + [ + 'name' => 'sugar, white', 'unit' => 'cup', - 'calories' => 238, - 'protein' => 5.32, - 'fat' => 1.87, - 'carbohydrates' => 49.6 + 'calories' => 770, + 'protein' => 0, + 'fat' => 0.54, + 'carbohydrates' => 199 + ], + [ + 'name' => 'vegetable oil', + 'unit' => 'tbsp', + 'calories' => 124, + 'protein' => 0, + 'fat' => 14, + 'carbohydrates' => 199 ], ]; Ingredient::factory()->createMany($default_ingredients); diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php new file mode 100644 index 0000000..550c8fa --- /dev/null +++ b/database/seeders/RecipeSeeder.php @@ -0,0 +1,74 @@ +create(['name' => 'pancakes']); + + $weight = 0; + $amounts = [ + [ + 'ingredient_id' => Ingredient::where('name', 'flour, all-purpose') + ->first()->id, + 'amount' => 1, + 'recipe_id' => $recipe->id, + 'weight' => $weight++, + ], + [ + 'ingredient_id' => Ingredient::where('name', 'sugar, white') + ->first()->id, + 'amount' => 0.125, + 'recipe_id' => $recipe->id, + 'weight' => $weight++, + ], + [ + 'ingredient_id' => Ingredient::where('name', 'baking powder') + ->first()->id, + 'amount' => 2, + 'recipe_id' => $recipe->id, + 'weight' => $weight++, + ], + [ + 'ingredient_id' => Ingredient::where('name', 'salt') + ->first()->id, + 'amount' => 1, + 'recipe_id' => $recipe->id, + 'weight' => $weight++, + ], + [ + 'ingredient_id' => Ingredient::where('name', 'egg') + ->first()->id, + 'amount' => 1, + 'recipe_id' => $recipe->id, + 'weight' => $weight++, + ], + [ + 'ingredient_id' => Ingredient::where('name', 'milk, whole') + ->first()->id, + 'amount' => 1, + 'recipe_id' => $recipe->id, + 'weight' => $weight++, + ], + [ + 'ingredient_id' => Ingredient::where('name', 'vegetable oil') + ->first()->id, + 'amount' => 2, + 'recipe_id' => $recipe->id, + 'weight' => $weight++, + ], + ]; + IngredientAmount::factory()->createMany($amounts); + } +}