2022-02-07 21:50:25 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use App\Recipe;
|
|
|
|
|
use App\RecipeIngredient;
|
2022-02-11 23:02:48 -06:00
|
|
|
use App\RecipeCategory;
|
2022-02-07 21:50:25 -06:00
|
|
|
use App\User;
|
|
|
|
|
|
|
|
|
|
class RecipeController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
2022-02-12 02:41:03 -06:00
|
|
|
$recipes = Recipe::with('user')->get();
|
2022-02-11 23:02:48 -06:00
|
|
|
$categories=array_values(RecipeCategory::get()->sortby('name')->pluck('name')->unique()->toArray());
|
|
|
|
|
return view('recipes.index')->with('recipes', $recipes)->with('categories',$categories);
|
2022-02-07 21:50:25 -06:00
|
|
|
}
|
2022-02-12 02:41:03 -06:00
|
|
|
|
2022-02-07 21:50:25 -06:00
|
|
|
public function show($id)
|
|
|
|
|
{
|
2022-02-12 02:41:03 -06:00
|
|
|
$recipe=Recipe::with('user')->findOrFail($id);
|
2022-02-07 23:42:52 -06:00
|
|
|
return view('recipes.show')->with('recipe', $recipe);
|
2022-02-07 21:50:25 -06:00
|
|
|
}
|
2022-02-12 02:41:03 -06:00
|
|
|
|
2022-02-07 21:50:25 -06:00
|
|
|
public function edit($id){
|
2022-02-12 02:41:03 -06:00
|
|
|
$recipe=Recipe::with('user')->findOrFail($id);
|
|
|
|
|
$lists['ingredients']=array_values(RecipeIngredient::get()->sortby('name')->pluck('name')->unique()->toArray());
|
|
|
|
|
$lists['measurements']=array_values(RecipeIngredient::get()->sortby('measurement')->pluck('measurement')->unique()->toArray());
|
|
|
|
|
$lists['categories']=array_values(RecipeCategory::get()->sortby('name')->pluck('name')->unique()->toArray());
|
|
|
|
|
$lists['authors']=array_values(Recipe::get()->sortby('author')->pluck('author')->unique()->toArray());
|
|
|
|
|
$lists['owners']=array_values(User::get()->sortby('name')->pluck('name')->unique()->toArray());
|
|
|
|
|
return view('recipes.edit')->with('recipe', $recipe)->with('lists',$lists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
|
{
|
2022-02-07 21:50:25 -06:00
|
|
|
}
|
|
|
|
|
}
|