From a6e28a64aaab2651ceac96a70f7fc8f1ec08f27e Mon Sep 17 00:00:00 2001 From: Beth Parker Date: Mon, 7 Feb 2022 23:42:52 -0600 Subject: [PATCH] Added recipe page --- app/Http/Controllers/RecipeController.php | 4 +- app/Recipe.php | 11 +++++- ...2022_02_08_001417_create_recipes_table.php | 1 + database/seeders/RecipeSeeder.php | 8 ++-- public/css/layout.css | 5 +++ resources/views/recipes/index.blade.php | 2 +- resources/views/recipes/show.blade.php | 39 +++++++++++++++++++ 7 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 resources/views/recipes/show.blade.php diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php index 56aefe1..d6c2eea 100644 --- a/app/Http/Controllers/RecipeController.php +++ b/app/Http/Controllers/RecipeController.php @@ -17,8 +17,8 @@ class RecipeController extends Controller } public function show($id) { - $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id); - return $ingredients; + $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id); + return view('recipes.show')->with('recipe', $recipe); } public function edit($id){ $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id); diff --git a/app/Recipe.php b/app/Recipe.php index 34c9d05..665fd6a 100644 --- a/app/Recipe.php +++ b/app/Recipe.php @@ -4,11 +4,20 @@ namespace App; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Carbon\Carbon; class Recipe extends Model { - use HasFactory; protected $fillable = ['name','maintainer','author','servings','date_entered','date_modified','instructions']; + protected $dates = ['date_entered','date_modified']; + + public function setDateEnteredAttribute($value){ + $this->attributes['date_entered']=Carbon::parse($value); + } + + public function setDateModifiedAttribute($value){ + $this->attributes['date_modified']=Carbon::parse($value); + } public function user() { diff --git a/database/migrations/2022_02_08_001417_create_recipes_table.php b/database/migrations/2022_02_08_001417_create_recipes_table.php index 66b04b8..3fc5d35 100644 --- a/database/migrations/2022_02_08_001417_create_recipes_table.php +++ b/database/migrations/2022_02_08_001417_create_recipes_table.php @@ -19,6 +19,7 @@ class CreateRecipesTable extends Migration $table->unsignedInteger('user_id'); $table->string('author'); $table->unsignedInteger('servings'); + $table->string('serving_size'); $table->datetime('date_entered'); $table->datetime('date_modified'); $table->longtext('instructions'); diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php index 179c5ea..f8eaf04 100644 --- a/database/seeders/RecipeSeeder.php +++ b/database/seeders/RecipeSeeder.php @@ -18,20 +18,20 @@ class RecipeSeeder extends Seeder { $first_user = User::orderBy('id')->first(); - $recipe=Recipe::updateOrCreate(['name'=>'Test','user_id'=>$first_user['id'],'author'=>'Jayne','servings'=>1,'date_entered'=>now(),'date_modified'=>now(),'instructions'=>'These are instructions']); - + $recipe=Recipe::updateOrCreate(['name'=>'Test','user_id'=>$first_user['id'],'author'=>'Jayne','servings'=>1,'serving_size'=>'1 cup','date_entered'=>now(),'date_modified'=>now(),'instructions'=>'These are instructions']); RecipeIngredient::updateOrCreate(['recipe_id'=>$recipe['id'],'order'=>0,'alternative'=>false,'name'=>'hamburger','quantity'=>1.0,'measurement'=>'lb','special_notes'=>'']); RecipeIngredient::updateOrCreate(['recipe_id'=>$recipe['id'],'order'=>0,'alternative'=>true,'name'=>'sausage','quantity'=>1.0,'measurement'=>'lb','special_notes'=>'']); RecipeIngredient::updateOrCreate(['recipe_id'=>$recipe['id'],'order'=>0,'alternative'=>false,'name'=>'carrot','quantity'=>1.0,'measurement'=>'lb','special_notes'=>'']); - $recipe=Recipe::updateOrCreate(['name'=>'Test2','user_id'=>$first_user['id'],'author'=>'Karen','servings'=>1,'date_entered'=>now(),'date_modified'=>now(),'instructions'=>'These are instructions']); + + $recipe=Recipe::updateOrCreate(['name'=>'Test2','user_id'=>$first_user['id'],'author'=>'Karen','servings'=>1,'serving_size'=>'1 cup','date_entered'=>now(),'date_modified'=>now(),'instructions'=>'These are instructions']); RecipeIngredient::updateOrCreate(['recipe_id'=>$recipe['id'],'order'=>0,'alternative'=>false,'name'=>'chicken','quantity'=>1.0,'measurement'=>'lb','special_notes'=>'']); RecipeIngredient::updateOrCreate(['recipe_id'=>$recipe['id'],'order'=>0,'alternative'=>false,'name'=>'carrot','quantity'=>1.0,'measurement'=>'lb','special_notes'=>'']); $jayne=User::updateOrCreate(['name'=>'Jayne','email'=>'jayne.passmore@actcur.com','password'=>bcrypt('temp'),'created_at'=>NOW()]); - $recipe=Recipe::updateOrCreate(['name'=>'Test3','user_id'=>$jayne['id'],'author'=>'Jayne','servings'=>1,'date_entered'=>now(),'date_modified'=>now(),'instructions'=>'These are instructions']); + $recipe=Recipe::updateOrCreate(['name'=>'Test3','user_id'=>$jayne['id'],'author'=>'Jayne','servings'=>1,'serving_size'=>'1 cup','date_entered'=>now(),'date_modified'=>now(),'instructions'=>'These are instructions']); RecipeIngredient::updateOrCreate(['recipe_id'=>$recipe['id'],'order'=>0,'alternative'=>false,'name'=>'chicken','quantity'=>1.0,'measurement'=>'lb','special_notes'=>'']); RecipeIngredient::updateOrCreate(['recipe_id'=>$recipe['id'],'order'=>0,'alternative'=>false,'name'=>'carrot','quantity'=>1.0,'measurement'=>'lb','special_notes'=>'']); diff --git a/public/css/layout.css b/public/css/layout.css index 80c376c..2109ba4 100644 --- a/public/css/layout.css +++ b/public/css/layout.css @@ -11,6 +11,7 @@ --primary-highlight: #0000df;/*red*/ --primary-highlight-dark: #000064;/*20% darker*/ --secondary-highlight: #f80049;/*orange*/ + --input-color: #000000; } /***this is background***/ @@ -269,3 +270,7 @@ list { .operations{ width:132px; } + +input { + color: var(--input-color); +} diff --git a/resources/views/recipes/index.blade.php b/resources/views/recipes/index.blade.php index 5d883be..3eff563 100644 --- a/resources/views/recipes/index.blade.php +++ b/resources/views/recipes/index.blade.php @@ -26,7 +26,7 @@ @foreach ($recipes as $recipe) - {{ $recipe->name }} + {{ $recipe->name }} {{ $recipe->author }} {{ $recipe->user ->name}} diff --git a/resources/views/recipes/show.blade.php b/resources/views/recipes/show.blade.php new file mode 100644 index 0000000..5c4c4a9 --- /dev/null +++ b/resources/views/recipes/show.blade.php @@ -0,0 +1,39 @@ +@extends('layouts.default') +@extends('content_wrappers.md-10') + +@section('title', ' | '.$recipe->name) +@section('heading', $recipe->name) + +@section('content') +
+
+
Created By: {{$recipe->author}}
+
Maintained By: {{$recipe->user->name}}
+ +
Entered On: {{$recipe->date_entered->format('Y/m/d') }}
+
Last Changed: {{$recipe->date_modified->format('Y/m/d') }}
+
+
+
Servings: {{$recipe->servings}}
+
Serving Size: {{$recipe->serving_size}}
+
+
+

Ingredients

+ + @foreach ($recipe->ingredients as $index => $ingredient) + @if ($ingredient->alternative) + OR {{$ingredient->quantity}} {{$ingredient->measurement}} {{$ingredient->name}} + @else + @if($index != 0)
@endif +
{{$ingredient->quantity}} {{$ingredient->measurement}} {{$ingredient->name}} + @endif + @endforeach + @if(count($recipe->ingredients) > 0) +
+ @endif + +

+

Instructions

+
{{$recipe->instructions}}
+
+@endsection