Add `source` field to Recipe model

This commit is contained in:
Christopher C. Wells 2021-01-18 09:22:08 -08:00
parent f974806b15
commit 70c9396d0f
6 changed files with 56 additions and 4 deletions

View File

@ -105,6 +105,7 @@ class RecipeController extends Controller
$input = $request->validate([
'name' => 'required|string',
'description' => 'nullable|string',
'source' => 'nullable|string',
'servings' => 'required|numeric',
'foods_amount' => ['required', 'array', new ArrayNotEmpty],
'foods_amount.*' => ['required_with:foods.*', 'nullable', new StringIsDecimalOrFraction],
@ -121,6 +122,7 @@ class RecipeController extends Controller
$recipe->fill([
'name' => Str::lower($input['name']),
'description' => $input['description'],
'source' => $input['source'],
'servings' => (int) $input['servings'],
]);
@ -159,7 +161,8 @@ class RecipeController extends Controller
return back()->withInput()->withErrors("Failed to updated recipe due to database error: {$e->getMessage()}.");
}
return back()->with('message', "Recipe {$recipe->name} updated!");
session()->flash('message', "Recipe {$recipe->name} updated!");
return redirect()->route('recipes.show', $recipe);
}
/**

View File

@ -23,6 +23,7 @@ class Recipe extends Model
protected $fillable = [
'name',
'description',
'source',
'servings',
];

View File

@ -18,6 +18,7 @@ class CreateRecipesTable extends Migration
$table->string('name');
$table->string('slug')->unique();
$table->longText('description')->nullable();
$table->string('source')->nullable();
$table->unsignedInteger('servings');
$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 AddRecipeSourceColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('recipes', function (Blueprint $table) {
$table->string('source')->nullable()->after('description');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('recipes', function (Blueprint $table) {
$table->dropColumn('source');
});
}
}

View File

@ -64,6 +64,17 @@
name="description"
:value="old('description', $recipe->description)" />
</div>
<!-- Source -->
<div>
<x-inputs.label for="source" :value="__('Source')" />
<x-inputs.input id="source"
class="block mt-1 w-full"
type="text"
name="source"
:value="old('source', $recipe->source)" />
</div>
</div>
<!-- Ingredients -->

View File

@ -8,9 +8,13 @@
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6 bg-white border-b border-gray-200">
<div class="mb-2 text-gray-500 text-sm">
<span class="font-extrabold">Source:</span>
{{ $recipe->source }}
</div>
<h3 class="mb-2 font-bold">Description</h3>
<div class="text-gray-800">{{ $recipe->description }}</div>
<h3 class="mb-2 mt-4 font-bold">Ingredients</h3>
<div class="mb-2 text-gray-800">{{ $recipe->description }}</div>
<h3 class="mb-2 font-bold">Ingredients</h3>
@foreach($recipe->foodAmounts as $ia)
<div class="flex flex-row space-x-2 mb-2">
<div>{{ \App\Support\Number::fractionStringFromFloat($ia->amount) }}</div>
@ -19,7 +23,7 @@
@if($ia->detail)<div class="text-gray-500">{{ $ia->detail }}</div>@endif
</div>
@endforeach
<h3 class="mb-2 mt-4 font-bold">Steps</h3>
<h3 class="mb-2 font-bold">Steps</h3>
@foreach($recipe->steps as $step)
<div class="flex flex-row space-x-4 mb-4">
<div class="text-3xl text-gray-400 text-center">{{ $step->number }}</div>