mirror of https://github.com/kcal-app/kcal.git
Add `source` field to Recipe model
This commit is contained in:
parent
f974806b15
commit
70c9396d0f
|
@ -105,6 +105,7 @@ class RecipeController extends Controller
|
||||||
$input = $request->validate([
|
$input = $request->validate([
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'description' => 'nullable|string',
|
'description' => 'nullable|string',
|
||||||
|
'source' => 'nullable|string',
|
||||||
'servings' => 'required|numeric',
|
'servings' => 'required|numeric',
|
||||||
'foods_amount' => ['required', 'array', new ArrayNotEmpty],
|
'foods_amount' => ['required', 'array', new ArrayNotEmpty],
|
||||||
'foods_amount.*' => ['required_with:foods.*', 'nullable', new StringIsDecimalOrFraction],
|
'foods_amount.*' => ['required_with:foods.*', 'nullable', new StringIsDecimalOrFraction],
|
||||||
|
@ -121,6 +122,7 @@ class RecipeController extends Controller
|
||||||
$recipe->fill([
|
$recipe->fill([
|
||||||
'name' => Str::lower($input['name']),
|
'name' => Str::lower($input['name']),
|
||||||
'description' => $input['description'],
|
'description' => $input['description'],
|
||||||
|
'source' => $input['source'],
|
||||||
'servings' => (int) $input['servings'],
|
'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()->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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Recipe extends Model
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
|
'source',
|
||||||
'servings',
|
'servings',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ class CreateRecipesTable extends Migration
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('slug')->unique();
|
$table->string('slug')->unique();
|
||||||
$table->longText('description')->nullable();
|
$table->longText('description')->nullable();
|
||||||
|
$table->string('source')->nullable();
|
||||||
$table->unsignedInteger('servings');
|
$table->unsignedInteger('servings');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
|
@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,6 +64,17 @@
|
||||||
name="description"
|
name="description"
|
||||||
:value="old('description', $recipe->description)" />
|
:value="old('description', $recipe->description)" />
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
<!-- Ingredients -->
|
<!-- Ingredients -->
|
||||||
|
|
|
@ -8,9 +8,13 @@
|
||||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
<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="bg-white overflow-hidden shadow-sm sm:rounded-lg">
|
||||||
<div class="p-6 bg-white border-b border-gray-200">
|
<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>
|
<h3 class="mb-2 font-bold">Description</h3>
|
||||||
<div class="text-gray-800">{{ $recipe->description }}</div>
|
<div class="mb-2 text-gray-800">{{ $recipe->description }}</div>
|
||||||
<h3 class="mb-2 mt-4 font-bold">Ingredients</h3>
|
<h3 class="mb-2 font-bold">Ingredients</h3>
|
||||||
@foreach($recipe->foodAmounts as $ia)
|
@foreach($recipe->foodAmounts as $ia)
|
||||||
<div class="flex flex-row space-x-2 mb-2">
|
<div class="flex flex-row space-x-2 mb-2">
|
||||||
<div>{{ \App\Support\Number::fractionStringFromFloat($ia->amount) }}</div>
|
<div>{{ \App\Support\Number::fractionStringFromFloat($ia->amount) }}</div>
|
||||||
|
@ -19,7 +23,7 @@
|
||||||
@if($ia->detail)<div class="text-gray-500">{{ $ia->detail }}</div>@endif
|
@if($ia->detail)<div class="text-gray-500">{{ $ia->detail }}</div>@endif
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
<h3 class="mb-2 mt-4 font-bold">Steps</h3>
|
<h3 class="mb-2 font-bold">Steps</h3>
|
||||||
@foreach($recipe->steps as $step)
|
@foreach($recipe->steps as $step)
|
||||||
<div class="flex flex-row space-x-4 mb-4">
|
<div class="flex flex-row space-x-4 mb-4">
|
||||||
<div class="text-3xl text-gray-400 text-center">{{ $step->number }}</div>
|
<div class="text-3xl text-gray-400 text-center">{{ $step->number }}</div>
|
||||||
|
|
Loading…
Reference in New Issue