From 2dd92c8d3a9d039528b64dc349437ea39cb984a2 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Wed, 30 Dec 2020 15:06:22 -0800 Subject: [PATCH] Refactor "ingredients" as "foods" --- ...ontroller.php => FoodAmountController.php} | 20 ++++----- ...dientController.php => FoodController.php} | 32 +++++++------- app/Http/Controllers/RecipeController.php | 42 +++++++++---------- .../Adapter.php | 6 +-- .../Schema.php | 12 +++--- .../{Ingredients => Foods}/Adapter.php | 4 +- app/JsonApi/{Ingredients => Foods}/Schema.php | 6 +-- app/JsonApi/Recipes/Adapter.php | 2 +- app/JsonApi/Recipes/Schema.php | 6 +-- app/Models/{Ingredient.php => Food.php} | 15 ++++--- .../{IngredientAmount.php => FoodAmount.php} | 30 ++++++------- app/Models/Recipe.php | 16 +++---- config/json-api-default.php | 4 +- ...dientFactory.php => FoodAmountFactory.php} | 6 +-- ...dientAmountFactory.php => FoodFactory.php} | 6 +-- ... 2020_12_21_214128_create_foods_table.php} | 6 +-- ...2_21_215527_create_food_amounts_table.php} | 10 ++--- database/seeders/DatabaseSeeder.php | 2 +- .../{IngredientSeeder.php => FoodSeeder.php} | 8 ++-- database/seeders/RecipeSeeder.php | 20 ++++----- .../views/auth/confirm-password.blade.php | 8 ++-- .../views/auth/forgot-password.blade.php | 8 ++-- resources/views/auth/login.blade.php | 12 +++--- resources/views/auth/register.blade.php | 20 ++++----- resources/views/auth/reset-password.blade.php | 16 +++---- resources/views/auth/verify-email.blade.php | 4 +- .../{ingredients => foods}/create.blade.php | 4 +- .../{ingredients => foods}/index.blade.php | 24 +++++------ resources/views/layouts/navigation.blade.php | 12 +++--- resources/views/recipes/create.blade.php | 16 +++---- resources/views/recipes/show.blade.php | 4 +- routes/api.php | 8 ++-- routes/web.php | 4 +- 33 files changed, 199 insertions(+), 194 deletions(-) rename app/Http/Controllers/{IngredientAmountController.php => FoodAmountController.php} (67%) rename app/Http/Controllers/{IngredientController.php => FoodController.php} (67%) rename app/JsonApi/{IngredientAmounts => FoodAmounts}/Adapter.php (87%) rename app/JsonApi/{IngredientAmounts => FoodAmounts}/Schema.php (87%) rename app/JsonApi/{Ingredients => Foods}/Adapter.php (89%) rename app/JsonApi/{Ingredients => Foods}/Schema.php (88%) rename app/Models/{Ingredient.php => Food.php} (78%) rename app/Models/{IngredientAmount.php => FoodAmount.php} (70%) rename database/factories/{IngredientFactory.php => FoodAmountFactory.php} (77%) rename database/factories/{IngredientAmountFactory.php => FoodFactory.php} (74%) rename database/migrations/{2020_12_21_214128_create_ingredients_table.php => 2020_12_21_214128_create_foods_table.php} (85%) rename database/migrations/{2020_12_21_215527_create_ingredient_amounts_table.php => 2020_12_21_215527_create_food_amounts_table.php} (72%) rename database/seeders/{IngredientSeeder.php => FoodSeeder.php} (92%) rename resources/views/{ingredients => foods}/create.blade.php (98%) rename resources/views/{ingredients => foods}/index.blade.php (69%) diff --git a/app/Http/Controllers/IngredientAmountController.php b/app/Http/Controllers/FoodAmountController.php similarity index 67% rename from app/Http/Controllers/IngredientAmountController.php rename to app/Http/Controllers/FoodAmountController.php index a1e540b..961986c 100644 --- a/app/Http/Controllers/IngredientAmountController.php +++ b/app/Http/Controllers/FoodAmountController.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers; -use App\Models\IngredientAmount; +use App\Models\FoodAmount; use Illuminate\Http\Request; -class IngredientAmountController extends Controller +class FoodAmountController extends Controller { /** * Display a listing of the resource. @@ -41,10 +41,10 @@ class IngredientAmountController extends Controller /** * Display the specified resource. * - * @param \App\Models\IngredientAmount $ingredientAmount + * @param \App\Models\FoodAmount $foodAmount * @return \Illuminate\Http\Response */ - public function show(IngredientAmount $ingredientAmount) + public function show(FoodAmount $foodAmount) { // } @@ -52,10 +52,10 @@ class IngredientAmountController extends Controller /** * Show the form for editing the specified resource. * - * @param \App\Models\IngredientAmount $ingredientAmount + * @param \App\Models\FoodAmount $foodAmount * @return \Illuminate\Http\Response */ - public function edit(IngredientAmount $ingredientAmount) + public function edit(FoodAmount $foodAmount) { // } @@ -64,10 +64,10 @@ class IngredientAmountController extends Controller * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Models\IngredientAmount $ingredientAmount + * @param \App\Models\FoodAmount $foodAmount * @return \Illuminate\Http\Response */ - public function update(Request $request, IngredientAmount $ingredientAmount) + public function update(Request $request, FoodAmount $foodAmount) { // } @@ -75,10 +75,10 @@ class IngredientAmountController extends Controller /** * Remove the specified resource from storage. * - * @param \App\Models\IngredientAmount $ingredientAmount + * @param \App\Models\FoodAmount $foodAmount * @return \Illuminate\Http\Response */ - public function destroy(IngredientAmount $ingredientAmount) + public function destroy(FoodAmount $foodAmount) { // } diff --git a/app/Http/Controllers/IngredientController.php b/app/Http/Controllers/FoodController.php similarity index 67% rename from app/Http/Controllers/IngredientController.php rename to app/Http/Controllers/FoodController.php index a62195a..25db787 100644 --- a/app/Http/Controllers/IngredientController.php +++ b/app/Http/Controllers/FoodController.php @@ -2,12 +2,12 @@ namespace App\Http\Controllers; -use App\Models\Ingredient; +use App\Models\Food; use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -class IngredientController extends Controller +class FoodController extends Controller { /** * Display a listing of the resource. @@ -16,8 +16,8 @@ class IngredientController extends Controller */ public function index(): View { - return view('ingredients.index') - ->with('ingredients', Ingredient::all()->sortBy('name')); + return view('foods.index') + ->with('foods', Food::all()->sortBy('name')); } /** @@ -27,7 +27,7 @@ class IngredientController extends Controller */ public function create(): View { - return view('ingredients.create'); + return view('foods.create'); } /**newly @@ -47,18 +47,18 @@ class IngredientController extends Controller 'unit_weight' => 'required_without:cup_weight|nullable|numeric', 'cup_weight' => 'required_without:unit_weight|nullable|numeric', ]); - /** @var \App\Models\Ingredient $ingredient */ - $ingredient = tap(new Ingredient(array_filter($attributes)))->save(); - return back()->with('message', "Ingredient {$ingredient->name} added!"); + /** @var \App\Models\Food $food */ + $food = tap(new Food(array_filter($attributes)))->save(); + return back()->with('message', "Food {$food->name} added!"); } /** * Display the specified resource. * - * @param \App\Models\Ingredient $ingredient + * @param \App\Models\Food $food * @return \Illuminate\Http\Response */ - public function show(Ingredient $ingredient) + public function show(Food $food) { // } @@ -66,10 +66,10 @@ class IngredientController extends Controller /** * Show the form for editing the specified resource. * - * @param \App\Models\Ingredient $ingredient + * @param \App\Models\Food $food * @return \Illuminate\Http\Response */ - public function edit(Ingredient $ingredient) + public function edit(Food $food) { // } @@ -78,10 +78,10 @@ class IngredientController extends Controller * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request - * @param \App\Models\Ingredient $ingredient + * @param \App\Models\Food $food * @return \Illuminate\Http\Response */ - public function update(Request $request, Ingredient $ingredient) + public function update(Request $request, Food $food) { // } @@ -89,10 +89,10 @@ class IngredientController extends Controller /** * Remove the specified resource from storage. * - * @param \App\Models\Ingredient $ingredient + * @param \App\Models\Food $food * @return \Illuminate\Http\Response */ - public function destroy(Ingredient $ingredient) + public function destroy(Food $food) { // } diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php index b305f70..b79c3a4 100644 --- a/app/Http/Controllers/RecipeController.php +++ b/app/Http/Controllers/RecipeController.php @@ -2,8 +2,8 @@ namespace App\Http\Controllers; -use App\Models\Ingredient; -use App\Models\IngredientAmount; +use App\Models\Food; +use App\Models\FoodAmount; use App\Models\Recipe; use App\Models\RecipeStep; use App\Rules\ArrayNotEmpty; @@ -33,16 +33,16 @@ class RecipeController extends Controller */ public function create(): View { - $ingredients = Ingredient::all(['id', 'name', 'detail'])->collect() - ->map(function ($ingredient) { + $foods = Food::all(['id', 'name', 'detail'])->collect() + ->map(function ($food) { return [ - 'value' => $ingredient->id, - 'label' => "{$ingredient->name}" . ($ingredient->detail ? ", {$ingredient->detail}" : ""), + 'value' => $food->id, + 'label' => "{$food->name}" . ($food->detail ? ", {$food->detail}" : ""), ]; }); return view('recipes.create') - ->with('ingredients', $ingredients) - ->with('ingredient_units', new Collection([ + ->with('foods', $foods) + ->with('food_units', new Collection([ ['value' => 'tsp', 'label' => 'tsp.'], ['value' => 'tbsp', 'label' => 'tbsp.'], ['value' => 'cup', 'label' => 'cup'], @@ -62,12 +62,12 @@ class RecipeController extends Controller 'name' => 'required|string', 'description' => 'required|string', 'servings' => 'required|numeric', - 'ingredients_amount' => ['required', 'array', new ArrayNotEmpty], - 'ingredients_amount.*' => 'required_with:ingredients.*|nullable|numeric|min:0', - 'ingredients_unit' => ['required', 'array', new ArrayNotEmpty], - 'ingredients_unit.*' => 'nullable|string', - 'ingredients' => ['required', 'array', new ArrayNotEmpty], - 'ingredients.*' => 'required_with:ingredients_amount.*|nullable|exists:App\Models\Ingredient,id', + 'foods_amount' => ['required', 'array', new ArrayNotEmpty], + 'foods_amount.*' => 'required_with:foods.*|nullable|numeric|min:0', + 'foods_unit' => ['required', 'array', new ArrayNotEmpty], + 'foods_unit.*' => 'nullable|string', + 'foods' => ['required', 'array', new ArrayNotEmpty], + 'foods.*' => 'required_with:foods_amount.*|nullable|exists:App\Models\Food,id', 'steps' => ['required', 'array', new ArrayNotEmpty], 'steps.*' => 'nullable|string', ]); @@ -84,17 +84,17 @@ class RecipeController extends Controller return; } - $ingredient_amounts = []; + $food_amounts = []; $weight = 0; - foreach (array_filter($input['ingredients_amount']) as $key => $amount) { - $ingredient_amounts[$key] = new IngredientAmount([ + foreach (array_filter($input['foods_amount']) as $key => $amount) { + $food_amounts[$key] = new FoodAmount([ 'amount' => (float) $amount, - 'unit' => $input['ingredients_unit'][$key], + 'unit' => $input['foods_unit'][$key], 'weight' => $weight++, ]); - $ingredient_amounts[$key]->ingredient()->associate($input['ingredients'][$key]); + $food_amounts[$key]->food()->associate($input['foods'][$key]); } - $recipe->ingredientAmounts()->saveMany($ingredient_amounts); + $recipe->foodAmounts()->saveMany($food_amounts); $steps = []; $number = 1; @@ -104,7 +104,7 @@ class RecipeController extends Controller 'step' => $step, ]); } - $recipe->ingredientAmounts()->saveMany($steps); + $recipe->foodAmounts()->saveMany($steps); }); } catch (\Exception $e) { DB::rollBack(); diff --git a/app/JsonApi/IngredientAmounts/Adapter.php b/app/JsonApi/FoodAmounts/Adapter.php similarity index 87% rename from app/JsonApi/IngredientAmounts/Adapter.php rename to app/JsonApi/FoodAmounts/Adapter.php index 46d0cf9..ca21d6a 100644 --- a/app/JsonApi/IngredientAmounts/Adapter.php +++ b/app/JsonApi/FoodAmounts/Adapter.php @@ -1,6 +1,6 @@ filterWithScopes($query, $filters); } - protected function ingredient(): BelongsTo + protected function food(): BelongsTo { return $this->belongsTo(); } diff --git a/app/JsonApi/IngredientAmounts/Schema.php b/app/JsonApi/FoodAmounts/Schema.php similarity index 87% rename from app/JsonApi/IngredientAmounts/Schema.php rename to app/JsonApi/FoodAmounts/Schema.php index 07ab271..c269984 100644 --- a/app/JsonApi/IngredientAmounts/Schema.php +++ b/app/JsonApi/FoodAmounts/Schema.php @@ -1,6 +1,6 @@ [ + 'food' => [ self::SHOW_SELF => true, self::SHOW_RELATED => true, - self::SHOW_DATA => isset($includeRelationships['ingredient']), + self::SHOW_DATA => isset($includeRelationships['food']), self::DATA => function () use ($resource) { - return $resource->ingredient; + return $resource->food; }, ], 'recipe' => [ diff --git a/app/JsonApi/Ingredients/Adapter.php b/app/JsonApi/Foods/Adapter.php similarity index 89% rename from app/JsonApi/Ingredients/Adapter.php rename to app/JsonApi/Foods/Adapter.php index 25d98e8..cec50fb 100644 --- a/app/JsonApi/Ingredients/Adapter.php +++ b/app/JsonApi/Foods/Adapter.php @@ -1,6 +1,6 @@ filterWithScopes($query, $filters); } - protected function ingredientAmounts(): HasMany + protected function foodAmounts(): HasMany { return $this->hasMany(); } diff --git a/app/JsonApi/Recipes/Schema.php b/app/JsonApi/Recipes/Schema.php index 741d0f5..8837388 100644 --- a/app/JsonApi/Recipes/Schema.php +++ b/app/JsonApi/Recipes/Schema.php @@ -62,12 +62,12 @@ class Schema extends SchemaProvider return $resource->steps; }, ], - 'ingredient-amounts' => [ + 'food-amounts' => [ self::SHOW_SELF => true, self::SHOW_RELATED => true, - self::SHOW_DATA => isset($includeRelationships['ingredient-amounts']), + self::SHOW_DATA => isset($includeRelationships['food-amounts']), self::DATA => function () use ($resource) { - return $resource->ingredientAmounts; + return $resource->foodAmounts; }, ] ]; diff --git a/app/Models/Ingredient.php b/app/Models/Food.php similarity index 78% rename from app/Models/Ingredient.php rename to app/Models/Food.php index 837c9da..435a4c5 100644 --- a/app/Models/Ingredient.php +++ b/app/Models/Food.php @@ -7,23 +7,28 @@ use Illuminate\Database\Eloquent\Model; /** * @property int id - * @property string name Ingredient base name. - * @property ?string detail Some additional detail about the ingredient (e.g. "small" with the name "onion"). + * @property string name Food base name. + * @property ?string detail Some additional detail about the food (e.g. "small" with the name "onion"). * @property float carbohydrates (per 100g). * @property float calories (per 100g). * @property float cholesterol (per 100g). * @property float fat (per 100g). * @property float protein (per 100g). * @property float sodium (per 100g). - * @property ?float unit_weight Weight of one cup of the ingredient. - * @property ?float cup_weight Weight of one "unit" (e.g. an egg, onion, etc.) of the ingredient. + * @property ?float unit_weight Weight of one cup of the food. + * @property ?float cup_weight Weight of one "unit" (e.g. an egg, onion, etc.) of the food. * @property \Illuminate\Support\Carbon created_at * @property \Illuminate\Support\Carbon updated_at */ -class Ingredient extends Model +class Food extends Model { use HasFactory; + /** + * @inheritdoc + */ + protected $table = 'foods'; + /** * @inheritdoc */ diff --git a/app/Models/IngredientAmount.php b/app/Models/FoodAmount.php similarity index 70% rename from app/Models/IngredientAmount.php rename to app/Models/FoodAmount.php index 284e222..cd7ab3b 100644 --- a/app/Models/IngredientAmount.php +++ b/app/Models/FoodAmount.php @@ -8,10 +8,10 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * @property int id - * @property float amount Amount of ingredient. - * @property ?string unit Ingredient unit (tsp, tbsp, cup, or grams). - * @property int weight Weight of ingredient in full ingredient list (lowest first). - * @property \App\Models\Ingredient ingredient + * @property float amount Amount of food. + * @property ?string unit Food unit (tsp, tbsp, cup, or grams). + * @property int weight Weight of food in full food list (lowest first). + * @property \App\Models\Food food * @property \App\Models\Recipe recipe * @property \Illuminate\Support\Carbon created_at * @property \Illuminate\Support\Carbon updated_at @@ -22,7 +22,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @method float protein Get total protein. * @method float sodium Get total sodium. */ -class IngredientAmount extends Model +class FoodAmount extends Model { use HasFactory; @@ -46,7 +46,7 @@ class IngredientAmount extends Model /** * @inheritdoc */ - protected $with = ['ingredient']; + protected $with = ['food']; /** * Nutrient calculation methods. @@ -61,10 +61,10 @@ class IngredientAmount extends Model ]; /** - * Get the Ingredient this amount belongs to. + * Get the Food this amount belongs to. */ - public function ingredient(): BelongsTo { - return $this->belongsTo(Ingredient::class); + public function food(): BelongsTo { + return $this->belongsTo(Food::class); } /** @@ -86,7 +86,7 @@ class IngredientAmount extends Model */ public function __call($method, $parameters): mixed { if (in_array($method, $this->nutrientMethods)) { - return $this->ingredient->{$method} * $this->unitMultiplier(); + return $this->food->{$method} * $this->unitMultiplier(); } else { return parent::__call($method, $parameters); @@ -94,19 +94,19 @@ class IngredientAmount extends Model } /** - * Get the multiplier for the ingredient unit based on weight. + * Get the multiplier for the food unit based on weight. * - * Unit weight will be specified for ingredients that are added by unit + * Unit weight will be specified for foods that are added by unit * (e.g. eggs, vegetables, etc.) and cup weight (the weight of the - * ingredient equal to one cup) will be specified for ingredients that are + * food equal to one cup) will be specified for foods that are * measured (e.g. flour, milk, etc.). */ private function unitMultiplier(): float { return match ($this->unit) { - null => $this->ingredient->unit_weight, + null => $this->food->unit_weight, 'tsp' => 1/48, 'tbsp' => 1/16, default => 1 - } * $this->amount * ($this->ingredient->cup_weight ?? 1) / 100; + } * $this->amount * ($this->food->cup_weight ?? 1) / 100; } } diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index 92aab43..383bd8b 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property string description * @property int servings * @property \App\Models\RecipeStep[] steps - * @property \App\Models\IngredientAmount[] ingredientAmounts + * @property \App\Models\FoodAmount[] foodAmounts * @property \Illuminate\Support\Carbon created_at * @property \Illuminate\Support\Carbon updated_at * @method float caloriesTotal Get total calories. @@ -51,7 +51,7 @@ class Recipe extends Model /** * @inheritdoc */ - protected $with = ['steps', 'ingredientAmounts']; + protected $with = ['steps', 'foodAmounts']; /** * Nutrient total calculation methods. @@ -85,10 +85,10 @@ class Recipe extends Model } /** - * Get the Ingredient Amounts used for this Recipe. + * Get the Food Amounts used for this Recipe. */ - public function ingredientAmounts(): HasMany { - return $this->hasMany(IngredientAmount::class)->orderBy('weight'); + public function foodAmounts(): HasMany { + return $this->hasMany(FoodAmount::class)->orderBy('weight'); } /** @@ -123,7 +123,7 @@ class Recipe extends Model } /** - * Sum a specific nutrient for all ingredient amounts. + * Sum a specific nutrient for all food amounts. * * @param string $nutrient * Nutrient to sum. @@ -132,8 +132,8 @@ class Recipe extends Model */ private function sumNutrient(string $nutrient): float { $sum = 0; - foreach ($this->ingredientAmounts as $ingredientAmount) { - $sum += $ingredientAmount->{$nutrient}(); + foreach ($this->foodAmounts as $foodAmount) { + $sum += $foodAmount->{$nutrient}(); } return $sum; } diff --git a/config/json-api-default.php b/config/json-api-default.php index 96e2bb3..8d161d9 100644 --- a/config/json-api-default.php +++ b/config/json-api-default.php @@ -66,8 +66,8 @@ return [ | `'posts' => App\Post::class` */ 'resources' => [ - 'ingredients' => \App\Models\Ingredient::class, - 'ingredient-amounts' => \App\Models\IngredientAmount::class, + 'foods' => \App\Models\Food::class, + 'food-amounts' => \App\Models\FoodAmount::class, 'recipes' => \App\Models\Recipe::class, 'recipe-steps' => \App\Models\RecipeStep::class, ], diff --git a/database/factories/IngredientFactory.php b/database/factories/FoodAmountFactory.php similarity index 77% rename from database/factories/IngredientFactory.php rename to database/factories/FoodAmountFactory.php index 272367a..0ad8d10 100644 --- a/database/factories/IngredientFactory.php +++ b/database/factories/FoodAmountFactory.php @@ -2,17 +2,17 @@ namespace Database\Factories; -use App\Models\Ingredient; +use App\Models\FoodAmount; use Illuminate\Database\Eloquent\Factories\Factory; -class IngredientFactory extends Factory +class FoodAmountFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ - protected $model = Ingredient::class; + protected $model = FoodAmount::class; /** * Define the model's default state. diff --git a/database/factories/IngredientAmountFactory.php b/database/factories/FoodFactory.php similarity index 74% rename from database/factories/IngredientAmountFactory.php rename to database/factories/FoodFactory.php index 4735222..4cbd4cf 100644 --- a/database/factories/IngredientAmountFactory.php +++ b/database/factories/FoodFactory.php @@ -2,17 +2,17 @@ namespace Database\Factories; -use App\Models\IngredientAmount; +use App\Models\Food; use Illuminate\Database\Eloquent\Factories\Factory; -class IngredientAmountFactory extends Factory +class FoodFactory extends Factory { /** * The name of the factory's corresponding model. * * @var string */ - protected $model = IngredientAmount::class; + protected $model = Food::class; /** * Define the model's default state. diff --git a/database/migrations/2020_12_21_214128_create_ingredients_table.php b/database/migrations/2020_12_21_214128_create_foods_table.php similarity index 85% rename from database/migrations/2020_12_21_214128_create_ingredients_table.php rename to database/migrations/2020_12_21_214128_create_foods_table.php index bb7140d..6480c41 100644 --- a/database/migrations/2020_12_21_214128_create_ingredients_table.php +++ b/database/migrations/2020_12_21_214128_create_foods_table.php @@ -4,14 +4,14 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateIngredientsTable extends Migration +class CreateFoodsTable extends Migration { /** * Run the migrations. */ public function up(): void { - Schema::create('ingredients', function (Blueprint $table) { + Schema::create('foods', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('detail')->nullable(); @@ -32,6 +32,6 @@ class CreateIngredientsTable extends Migration */ public function down(): void { - Schema::dropIfExists('ingredients'); + Schema::dropIfExists('foods'); } } diff --git a/database/migrations/2020_12_21_215527_create_ingredient_amounts_table.php b/database/migrations/2020_12_21_215527_create_food_amounts_table.php similarity index 72% rename from database/migrations/2020_12_21_215527_create_ingredient_amounts_table.php rename to database/migrations/2020_12_21_215527_create_food_amounts_table.php index 6826648..61a0427 100644 --- a/database/migrations/2020_12_21_215527_create_ingredient_amounts_table.php +++ b/database/migrations/2020_12_21_215527_create_food_amounts_table.php @@ -1,12 +1,12 @@ id(); - $table->foreignIdFor(Ingredient::class); + $table->foreignIdFor(Food::class); $table->unsignedFloat('amount'); $table->enum('unit', ['tsp', 'tbsp', 'cup', 'grams'])->nullable(); $table->foreignIdFor(Recipe::class); @@ -33,6 +33,6 @@ class CreateIngredientAmountsTable extends Migration */ public function down() { - Schema::dropIfExists('ingredient_amounts'); + Schema::dropIfExists('food_amounts'); } } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 8a915b0..e3d088a 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -11,7 +11,7 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - $this->call(IngredientSeeder::class); + $this->call(FoodSeeder::class); $this->call(RecipeSeeder::class); } } diff --git a/database/seeders/IngredientSeeder.php b/database/seeders/FoodSeeder.php similarity index 92% rename from database/seeders/IngredientSeeder.php rename to database/seeders/FoodSeeder.php index 8aa4eca..b2574d8 100644 --- a/database/seeders/IngredientSeeder.php +++ b/database/seeders/FoodSeeder.php @@ -2,17 +2,17 @@ namespace Database\Seeders; -use App\Models\Ingredient; +use App\Models\Food; use Illuminate\Database\Seeder; -class IngredientSeeder extends Seeder +class FoodSeeder extends Seeder { /** * Run the database seeds. */ public function run(): void { - $default_ingredients = [ + $default_foods = [ [ 'name' => 'baking powder', 'calories' => 53, @@ -75,6 +75,6 @@ class IngredientSeeder extends Seeder 'cup_weight' => 224, ], ]; - Ingredient::factory()->createMany($default_ingredients); + Food::factory()->createMany($default_foods); } } diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php index a490807..b448023 100644 --- a/database/seeders/RecipeSeeder.php +++ b/database/seeders/RecipeSeeder.php @@ -2,8 +2,8 @@ namespace Database\Seeders; -use App\Models\Ingredient; -use App\Models\IngredientAmount; +use App\Models\Food; +use App\Models\FoodAmount; use App\Models\Recipe; use App\Models\RecipeStep; use Illuminate\Database\Seeder; @@ -25,7 +25,7 @@ class RecipeSeeder extends Seeder $weight = 0; $amounts = [ [ - 'ingredient_id' => Ingredient::where('name', 'flour') + 'food_id' => Food::where('name', 'flour') ->first()->id, 'amount' => 1, 'unit' => 'cup', @@ -33,7 +33,7 @@ class RecipeSeeder extends Seeder 'weight' => $weight++, ], [ - 'ingredient_id' => Ingredient::where('name', 'sugar') + 'food_id' => Food::where('name', 'sugar') ->first()->id, 'amount' => 2, 'unit' => 'tbsp', @@ -41,7 +41,7 @@ class RecipeSeeder extends Seeder 'weight' => $weight++, ], [ - 'ingredient_id' => Ingredient::where('name', 'baking powder') + 'food_id' => Food::where('name', 'baking powder') ->first()->id, 'amount' => 2, 'unit' => 'tsp', @@ -49,7 +49,7 @@ class RecipeSeeder extends Seeder 'weight' => $weight++, ], [ - 'ingredient_id' => Ingredient::where('name', 'salt') + 'food_id' => Food::where('name', 'salt') ->first()->id, 'amount' => 1, 'unit' => 'tsp', @@ -57,14 +57,14 @@ class RecipeSeeder extends Seeder 'weight' => $weight++, ], [ - 'ingredient_id' => Ingredient::where('name', 'egg') + 'food_id' => Food::where('name', 'egg') ->first()->id, 'amount' => 1, 'recipe_id' => $recipe->id, 'weight' => $weight++, ], [ - 'ingredient_id' => Ingredient::where('name', 'milk') + 'food_id' => Food::where('name', 'milk') ->first()->id, 'amount' => 1, 'unit' => 'cup', @@ -72,7 +72,7 @@ class RecipeSeeder extends Seeder 'weight' => $weight++, ], [ - 'ingredient_id' => Ingredient::where('name', 'vegetable oil') + 'food_id' => Food::where('name', 'vegetable oil') ->first()->id, 'amount' => 2, 'unit' => 'tbsp', @@ -80,7 +80,7 @@ class RecipeSeeder extends Seeder 'weight' => $weight++, ], ]; - IngredientAmount::factory()->createMany($amounts); + FoodAmount::factory()->createMany($amounts); $steps = [ [ diff --git a/resources/views/auth/confirm-password.blade.php b/resources/views/auth/confirm-password.blade.php index 466593a..0b15a9f 100644 --- a/resources/views/auth/confirm-password.blade.php +++ b/resources/views/auth/confirm-password.blade.php @@ -18,18 +18,18 @@
- + -
- + {{ __('Confirm') }} - +
diff --git a/resources/views/auth/forgot-password.blade.php b/resources/views/auth/forgot-password.blade.php index 0642fa8..66937f3 100644 --- a/resources/views/auth/forgot-password.blade.php +++ b/resources/views/auth/forgot-password.blade.php @@ -21,15 +21,15 @@
- + - +
- + {{ __('Email Password Reset Link') }} - +
diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 843c1cf..453039e 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -17,16 +17,16 @@
- + - +
- + - @@ -47,9 +47,9 @@ @endif - + {{ __('Login') }} - +
diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index a0c4fbe..af17d99 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -14,23 +14,23 @@
- + - +
- + - +
- + - @@ -38,9 +38,9 @@
- + -
@@ -50,9 +50,9 @@ {{ __('Already registered?') }} - + {{ __('Register') }} - +
diff --git a/resources/views/auth/reset-password.blade.php b/resources/views/auth/reset-password.blade.php index 979d1b4..8da6ed3 100644 --- a/resources/views/auth/reset-password.blade.php +++ b/resources/views/auth/reset-password.blade.php @@ -17,31 +17,31 @@
- + - +
- + - +
- + -
- + {{ __('Reset Password') }} - +
diff --git a/resources/views/auth/verify-email.blade.php b/resources/views/auth/verify-email.blade.php index ce71881..877a351 100644 --- a/resources/views/auth/verify-email.blade.php +++ b/resources/views/auth/verify-email.blade.php @@ -21,9 +21,9 @@ @csrf
- + {{ __('Resend Verification Email') }} - +
diff --git a/resources/views/ingredients/create.blade.php b/resources/views/foods/create.blade.php similarity index 98% rename from resources/views/ingredients/create.blade.php rename to resources/views/foods/create.blade.php index daf6cd3..8f5dfe8 100644 --- a/resources/views/ingredients/create.blade.php +++ b/resources/views/foods/create.blade.php @@ -1,7 +1,7 @@

- {{ __('Add Ingredient') }} + {{ __('Add Food') }}

@@ -25,7 +25,7 @@
-
+ @csrf
diff --git a/resources/views/ingredients/index.blade.php b/resources/views/foods/index.blade.php similarity index 69% rename from resources/views/ingredients/index.blade.php rename to resources/views/foods/index.blade.php index 5715d2e..3082d4a 100644 --- a/resources/views/ingredients/index.blade.php +++ b/resources/views/foods/index.blade.php @@ -1,7 +1,7 @@

- {{ __('Ingredients') }} + {{ __('Foods') }}

@@ -15,34 +15,34 @@
- @foreach ($ingredients as $ingredient) + @foreach ($foods as $food)
- {{ $ingredient->name }}@if($ingredient->detail), {{ $ingredient->detail }}@endif + {{ $food->name }}@if($food->detail), {{ $food->detail }}@endif
- @if ($ingredient->unit_weight) - {{ $ingredient->unit_weight }}g each + @if ($food->unit_weight) + {{ $food->unit_weight }}g each @else - {{ $ingredient->cup_weight }}g per cup + {{ $food->cup_weight }}g per cup @endif
Amount per 100g
Calories
-
{{$ingredient->calories}}
+
{{$food->calories}}
Fat
-
{{ $ingredient->fat < 1 ? $ingredient->fat * 1000 . "m" : $ingredient->fat }}g
+
{{ $food->fat < 1 ? $food->fat * 1000 . "m" : $food->fat }}g
Cholesterol
-
{{ $ingredient->cholesterol < 1 ? $ingredient->cholesterol * 1000 . "m" : $ingredient->cholesterol }}g
+
{{ $food->cholesterol < 1 ? $food->cholesterol * 1000 . "m" : $food->cholesterol }}g
Sodium
-
{{ $ingredient->sodium < 1 ? $ingredient->sodium * 1000 . "m" : $ingredient->sodium }}g
+
{{ $food->sodium < 1 ? $food->sodium * 1000 . "m" : $food->sodium }}g
Carbohydrates
-
{{ $ingredient->carbohydrates < 1 ? $ingredient->carbohydrates * 1000 . "m" : $ingredient->carbohydrates }}g
+
{{ $food->carbohydrates < 1 ? $food->carbohydrates * 1000 . "m" : $food->carbohydrates }}g
Protein
-
{{ $ingredient->protein < 1 ? $ingredient->protein * 1000 . "m" : $ingredient->protein }}g
+
{{ $food->protein < 1 ? $food->protein * 1000 . "m" : $food->protein }}g
@endforeach diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 23b9b33..ab63fff 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -43,12 +43,12 @@
- +