diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php index b445669..3c689f2 100644 --- a/app/Http/Controllers/RecipeController.php +++ b/app/Http/Controllers/RecipeController.php @@ -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); } /** diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index 4eb5229..28e8367 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -23,6 +23,7 @@ class Recipe extends Model protected $fillable = [ 'name', 'description', + 'source', 'servings', ]; diff --git a/database/migrations/2020_12_21_215932_create_recipes_table.php b/database/migrations/2020_12_21_215932_create_recipes_table.php index db22489..a487360 100644 --- a/database/migrations/2020_12_21_215932_create_recipes_table.php +++ b/database/migrations/2020_12_21_215932_create_recipes_table.php @@ -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(); }); diff --git a/database/migrations/2021_01_18_090224_add_recipe_source_column.php b/database/migrations/2021_01_18_090224_add_recipe_source_column.php new file mode 100644 index 0000000..89743a2 --- /dev/null +++ b/database/migrations/2021_01_18_090224_add_recipe_source_column.php @@ -0,0 +1,32 @@ +string('source')->nullable()->after('description'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('recipes', function (Blueprint $table) { + $table->dropColumn('source'); + }); + } +} diff --git a/resources/views/recipes/edit.blade.php b/resources/views/recipes/edit.blade.php index eb2bbe6..bc7fa43 100644 --- a/resources/views/recipes/edit.blade.php +++ b/resources/views/recipes/edit.blade.php @@ -64,6 +64,17 @@ name="description" :value="old('description', $recipe->description)" /> + + +
+ + + +
diff --git a/resources/views/recipes/show.blade.php b/resources/views/recipes/show.blade.php index 5360c71..390e3d3 100644 --- a/resources/views/recipes/show.blade.php +++ b/resources/views/recipes/show.blade.php @@ -8,9 +8,13 @@
+
+ Source: + {{ $recipe->source }} +

Description

-
{{ $recipe->description }}
-

Ingredients

+
{{ $recipe->description }}
+

Ingredients

@foreach($recipe->foodAmounts as $ia)
{{ \App\Support\Number::fractionStringFromFloat($ia->amount) }}
@@ -19,7 +23,7 @@ @if($ia->detail)
{{ $ia->detail }}
@endif
@endforeach -

Steps

+

Steps

@foreach($recipe->steps as $step)
{{ $step->number }}