diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php
index d6c2eea..88ea1fe 100644
--- a/app/Http/Controllers/RecipeController.php
+++ b/app/Http/Controllers/RecipeController.php
@@ -5,19 +5,20 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Recipe;
use App\RecipeIngredient;
+use App\RecipeCategory;
use App\User;
class RecipeController extends Controller
{
public function index()
{
- //Pass all users
- $recipes = Recipe::with('user')->get();
- return view('recipes.index')->with('recipes', $recipes);
+ $recipes = Recipe::with('user')->with('categories')->get();
+ $categories=array_values(RecipeCategory::get()->sortby('name')->pluck('name')->unique()->toArray());
+ return view('recipes.index')->with('recipes', $recipes)->with('categories',$categories);
}
public function show($id)
{
- $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id);
+ $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id);
return view('recipes.show')->with('recipe', $recipe);
}
public function edit($id){
diff --git a/app/Recipe.php b/app/Recipe.php
index 665fd6a..f3bc920 100644
--- a/app/Recipe.php
+++ b/app/Recipe.php
@@ -28,4 +28,9 @@ class Recipe extends Model
{
return $this->hasMany('App\RecipeIngredient');
}
+
+ public function categories()
+ {
+ return $this->hasMany('App\RecipeCategory');
+ }
}
diff --git a/app/RecipeCategory.php b/app/RecipeCategory.php
new file mode 100644
index 0000000..b610535
--- /dev/null
+++ b/app/RecipeCategory.php
@@ -0,0 +1,17 @@
+belongsTo('App\Recipe');
+ }
+}
diff --git a/database/migrations/2022_02_12_000441_create_recipe_category_table.php b/database/migrations/2022_02_12_000441_create_recipe_category_table.php
new file mode 100644
index 0000000..857f1d8
--- /dev/null
+++ b/database/migrations/2022_02_12_000441_create_recipe_category_table.php
@@ -0,0 +1,35 @@
+id();
+ $table->unsignedInteger('recipe_id');
+ $table->string('name');
+ $table->timestamps();
+
+ $table->foreign('recipe_id')->references('id')->on('recipes');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('recipe_category');
+ }
+}
diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php
index f8eaf04..459f2a0 100644
--- a/database/seeders/RecipeSeeder.php
+++ b/database/seeders/RecipeSeeder.php
@@ -6,6 +6,7 @@ use Illuminate\Database\Seeder;
use App\User;
use App\Recipe;
use App\RecipeIngredient;
+use App\RecipeCategory;
class RecipeSeeder extends Seeder
{
@@ -23,6 +24,9 @@ class RecipeSeeder extends Seeder
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'=>'']);
+ RecipeCategory::updateOrCreate(['recipe_id'=>$recipe['id'],'name'=>'breakfast']);
+
+
$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']);
@@ -31,9 +35,18 @@ class RecipeSeeder extends Seeder
$jayne=User::updateOrCreate(['name'=>'Jayne','email'=>'jayne.passmore@actcur.com','password'=>bcrypt('temp'),'created_at'=>NOW()]);
+ RecipeCategory::updateOrCreate(['recipe_id'=>$recipe['id'],'name'=>'entree']);
+ RecipeCategory::updateOrCreate(['recipe_id'=>$recipe['id'],'name'=>'mexican']);
+
+
$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'=>'']);
+
+ RecipeCategory::updateOrCreate(['recipe_id'=>$recipe['id'],'name'=>'entree']);
+ RecipeCategory::updateOrCreate(['recipe_id'=>$recipe['id'],'name'=>'mexican']);
+ RecipeCategory::updateOrCreate(['recipe_id'=>$recipe['id'],'name'=>'something']);
+
}
}
diff --git a/resources/views/recipes/index.blade.php b/resources/views/recipes/index.blade.php
index 3eff563..245f4db 100644
--- a/resources/views/recipes/index.blade.php
+++ b/resources/views/recipes/index.blade.php
@@ -1,5 +1,5 @@
@extends('layouts.default')
-@extends('content_wrappers.md-10')
+@extends('content_wrappers.md-12')
@section('title', '| Recipes')
@section('heading', 'Recipes')
@@ -11,60 +11,82 @@
Name
+ Categories
Created By
- Maintainer
- Operations
+ @if(Auth::user())
+ Operations
+ @endif