Add `detail` field to Food Amount model

This commit is contained in:
Christopher C. Wells 2021-01-18 08:59:55 -08:00
parent 38db1ce41d
commit f974806b15
9 changed files with 55 additions and 178 deletions

View File

@ -31,6 +31,8 @@ namespace App\Models{
* @property float $protein
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\FoodAmount[] $foodAmounts
* @property-read int|null $food_amounts_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\JournalEntry[] $journalEntries
* @property-read int|null $journal_entries_count
* @method static \Illuminate\Database\Eloquent\Builder|Food findSimilarSlugs(string $attribute, array $config, string $slug)
@ -54,7 +56,7 @@ namespace App\Models{
* @method static \Illuminate\Database\Eloquent\Builder|Food whereSodium($value)
* @method static \Illuminate\Database\Eloquent\Builder|Food whereUpdatedAt($value)
*/
class IdeHelperFood extends \Eloquent {}
class Food extends \Eloquent {}
}
namespace App\Models{
@ -70,6 +72,7 @@ namespace App\Models{
* @property int $weight
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $detail
* @property-read \App\Models\Food $food
* @property-read \App\Models\Recipe $recipe
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount newModelQuery()
@ -77,6 +80,7 @@ namespace App\Models{
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount query()
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount whereAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount whereDetail($value)
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount whereFoodId($value)
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount whereRecipeId($value)
@ -84,7 +88,7 @@ namespace App\Models{
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|FoodAmount whereWeight($value)
*/
class IdeHelperFoodAmount extends \Eloquent {}
class FoodAmount extends \Eloquent {}
}
namespace App\Models{
@ -127,7 +131,7 @@ namespace App\Models{
* @method static \Illuminate\Database\Eloquent\Builder|JournalEntry whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|JournalEntry whereUserId($value)
*/
class IdeHelperJournalEntry extends \Eloquent {}
class JournalEntry extends \Eloquent {}
}
namespace App\Models{
@ -138,10 +142,10 @@ namespace App\Models{
* @property int $id
* @property string $name
* @property string $slug
* @property string $description
* @property int $servings
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $description
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\FoodAmount[] $foodAmounts
* @property-read int|null $food_amounts_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\JournalEntry[] $journalEntries
@ -160,7 +164,7 @@ namespace App\Models{
* @method static \Illuminate\Database\Eloquent\Builder|Recipe whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|Recipe whereUpdatedAt($value)
*/
class IdeHelperRecipe extends \Eloquent {}
class Recipe extends \Eloquent {}
}
namespace App\Models{
@ -185,7 +189,7 @@ namespace App\Models{
* @method static \Illuminate\Database\Eloquent\Builder|RecipeStep whereStep($value)
* @method static \Illuminate\Database\Eloquent\Builder|RecipeStep whereUpdatedAt($value)
*/
class IdeHelperRecipeStep extends \Eloquent {}
class RecipeStep extends \Eloquent {}
}
namespace App\Models{
@ -215,6 +219,6 @@ namespace App\Models{
* @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
*/
class IdeHelperUser extends \Eloquent {}
class User extends \Eloquent {}
}

View File

@ -1,85 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Models\FoodAmount;
use Illuminate\Http\Request;
class FoodAmountController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Models\FoodAmount $foodAmount
* @return \Illuminate\Http\Response
*/
public function show(FoodAmount $foodAmount)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\FoodAmount $foodAmount
* @return \Illuminate\Http\Response
*/
public function edit(FoodAmount $foodAmount)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\FoodAmount $foodAmount
* @return \Illuminate\Http\Response
*/
public function update(Request $request, FoodAmount $foodAmount)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\FoodAmount $foodAmount
* @return \Illuminate\Http\Response
*/
public function destroy(FoodAmount $foodAmount)
{
//
}
}

View File

@ -110,6 +110,8 @@ class RecipeController extends Controller
'foods_amount.*' => ['required_with:foods.*', 'nullable', new StringIsDecimalOrFraction],
'foods_unit' => ['required', 'array'],
'foods_unit.*' => 'nullable|string',
'foods_detail' => ['required', 'array'],
'foods_detail.*' => 'nullable|string',
'foods' => ['required', 'array', new ArrayNotEmpty],
'foods.*' => 'required_with:foods_amount.*|nullable|exists:App\Models\Food,id',
'steps' => ['required', 'array', new ArrayNotEmpty],
@ -136,6 +138,7 @@ class RecipeController extends Controller
$food_amounts[$key]->fill([
'amount' => Number::floatFromString($amount),
'unit' => $input['foods_unit'][$key],
'detail' => $input['foods_detail'][$key],
'weight' => $weight++,
]);
$food_amounts[$key]->food()->associate($input['foods'][$key]);

View File

@ -1,85 +0,0 @@
<?php
namespace App\Http\Controllers;
use App\Models\RecipeStep;
use Illuminate\Http\Request;
class RecipeStepController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Models\RecipeStep $recipeStep
* @return \Illuminate\Http\Response
*/
public function show(RecipeStep $recipeStep)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\RecipeStep $recipeStep
* @return \Illuminate\Http\Response
*/
public function edit(RecipeStep $recipeStep)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\RecipeStep $recipeStep
* @return \Illuminate\Http\Response
*/
public function update(Request $request, RecipeStep $recipeStep)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\RecipeStep $recipeStep
* @return \Illuminate\Http\Response
*/
public function destroy(RecipeStep $recipeStep)
{
//
}
}

View File

@ -20,6 +20,7 @@ class FoodAmount extends Model
protected $fillable = [
'amount',
'unit',
'detail',
'weight',
];

View File

@ -20,6 +20,7 @@ class CreateFoodAmountsTable extends Migration
$table->foreignIdFor(Food::class)->index();
$table->unsignedFloat('amount');
$table->enum('unit', ['tsp', 'tbsp', 'cup', 'oz'])->nullable();
$table->string('detail')->nullable();
$table->foreignIdFor(Recipe::class)->index();
$table->unsignedInteger('weight');
$table->timestamps();

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddFoodAmountDetailColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('food_amounts', function (Blueprint $table) {
$table->string('detail')->nullable()->after('unit');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('food_amounts', function (Blueprint $table) {
$table->dropColumn('detail');
});
}
}

View File

@ -75,9 +75,10 @@
$amount = \App\Support\Number::fractionStringFromFloat($foodAmount->amount);
$unit = $foodAmount->unit;
$food_id = $foodAmount->food->id;
$detail = $foodAmount->detail;
} else {
$foodAmount = new \App\Models\FoodAmount();
$amount = $food_id = $unit = null;
$amount = $food_id = $unit = $detail = null;
}
@endphp
<div class="flex flex-row space-x-4 mb-4">
@ -95,6 +96,10 @@
:selectedValue="old('foods.' . $i, $food_id)">
<option value=""></option>
</x-inputs.select>
<x-inputs.input type="text"
class="block"
name="foods_detail[]"
:value="old('foods_detail.' . $i, $detail)" />
</div>
@endfor

View File

@ -16,6 +16,7 @@
<div>{{ \App\Support\Number::fractionStringFromFloat($ia->amount) }}</div>
@if($ia->unit)<div>{{ $ia->unit }}</div>@endif
<div>{{ $ia->food->name }}</div>
@if($ia->detail)<div class="text-gray-500">{{ $ia->detail }}</div>@endif
</div>
@endforeach
<h3 class="mb-2 mt-4 font-bold">Steps</h3>