forked from acearo/base-laravel
39 lines
1.4 KiB
PHP
39 lines
1.4 KiB
PHP
<?php
|
|
|
|
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()
|
|
{
|
|
$recipes = Recipe::with('user')->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')->findOrFail($id);
|
|
return view('recipes.show')->with('recipe', $recipe);
|
|
}
|
|
|
|
public function edit($id){
|
|
$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)
|
|
{
|
|
}
|
|
}
|