diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php new file mode 100644 index 0000000..56aefe1 --- /dev/null +++ b/app/Http/Controllers/RecipeController.php @@ -0,0 +1,28 @@ +get(); + return view('recipes.index')->with('recipes', $recipes); + } + public function show($id) + { + $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id); + return $ingredients; + } + public function edit($id){ + $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id); + $ingredients=RecipeIngredient::get()->sortby('name')->pluck('name')->unique(); + return $ingredients; + } +} diff --git a/app/Recipe.php b/app/Recipe.php index 98acda5..34c9d05 100644 --- a/app/Recipe.php +++ b/app/Recipe.php @@ -10,6 +10,11 @@ class Recipe extends Model use HasFactory; protected $fillable = ['name','maintainer','author','servings','date_entered','date_modified','instructions']; + public function user() + { + return $this->belongsTo('App\User'); + } + public function ingredients() { return $this->hasMany('App\RecipeIngredient'); diff --git a/app/User.php b/app/User.php index d69fdba..8ab8151 100644 --- a/app/User.php +++ b/app/User.php @@ -67,4 +67,8 @@ class User extends Authenticatable } return false; } + + public function recipes(){ + return $this->hasMany('App\Recipe'); + } } diff --git a/database/factories/RecipeFactory.php b/database/factories/RecipeFactory.php deleted file mode 100644 index c146cb1..0000000 --- a/database/factories/RecipeFactory.php +++ /dev/null @@ -1,17 +0,0 @@ -id(); $table->string('name'); - $table->unsignedInteger('maintainer'); + $table->unsignedInteger('user_id'); $table->string('author'); $table->unsignedInteger('servings'); $table->datetime('date_entered'); @@ -24,7 +24,7 @@ class CreateRecipesTable extends Migration $table->longtext('instructions'); $table->timestamps(); - $table->foreign('maintainer')->references('id')->on('users'); + $table->foreign('user_id')->references('id')->on('users'); }); } diff --git a/database/migrations/2022_02_08_003527_create_recipe_ingredient_table.php b/database/migrations/2022_02_08_012614_create_recipe_ingredients_table.php similarity index 81% rename from database/migrations/2022_02_08_003527_create_recipe_ingredient_table.php rename to database/migrations/2022_02_08_012614_create_recipe_ingredients_table.php index 096cfd8..ff4abeb 100644 --- a/database/migrations/2022_02_08_003527_create_recipe_ingredient_table.php +++ b/database/migrations/2022_02_08_012614_create_recipe_ingredients_table.php @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateRecipeIngredientTable extends Migration +class CreateRecipeIngredientsTable extends Migration { /** * Run the migrations. @@ -13,7 +13,7 @@ class CreateRecipeIngredientTable extends Migration */ public function up() { - Schema::create('recipe_ingredient', function (Blueprint $table) { + Schema::create('recipe_ingredients', function (Blueprint $table) { $table->id(); $table->unsignedInteger('recipe_id'); $table->unsignedInteger('order'); @@ -35,6 +35,6 @@ class CreateRecipeIngredientTable extends Migration */ public function down() { - Schema::dropIfExists('recipe_ingredient'); + Schema::dropIfExists('recipe_ingredients'); } } diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php new file mode 100644 index 0000000..179c5ea --- /dev/null +++ b/database/seeders/RecipeSeeder.php @@ -0,0 +1,39 @@ +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']); + + 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']); + + 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']); + + 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 5b3924b..80c376c 100644 --- a/public/css/layout.css +++ b/public/css/layout.css @@ -265,3 +265,7 @@ list { .fix-spacing{ padding-top: 30px; } + +.operations{ + width:132px; +} diff --git a/resources/views/recipes/index.blade.php b/resources/views/recipes/index.blade.php new file mode 100644 index 0000000..5d883be --- /dev/null +++ b/resources/views/recipes/index.blade.php @@ -0,0 +1,70 @@ +@extends('layouts.default') +@extends('content_wrappers.md-10') + +@section('title', '| Recipes') +@section('heading', 'Recipes') + +@section('content') +
+ + + + + + + + + + + + + + + + + + + @foreach ($recipes as $recipe) + + + + + + + @endforeach + +
NameCreated ByMaintainerOperations
{{ $recipe->name }}{{ $recipe->author }}{{ $recipe->user ->name}} + @if(in_array('EditRecipe',$allperms) || ( Auth::user() && $recipe->user_id == Auth::user()->id)) + Edit + @endif + + @if(in_array('DeleteRecipe',$allperms) || ( Auth::user() && $recipe->user_id == Auth::user()->id)) + {!! Form::open(['method' => 'DELETE', 'route' => ['recipes.destroy', $recipe->id] ]) !!} + {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!} + {!! Form::close() !!} + @endif +
+
+ + @if(in_array('Createrecipe',$allperms)) + Add recipe + @endif +@endsection + +@section('scripts') + +@endsection diff --git a/routes/web.php b/routes/web.php index 5d24e71..6b601df 100644 --- a/routes/web.php +++ b/routes/web.php @@ -37,4 +37,5 @@ Route::group(['middleware' => 'permissions:SHARE'], function(){ Route::resource('users','UserController'); Route::resource('roles','RoleController'); + Route::resource('recipes','RecipeController'); });