ldc-nature-and-respect/app/Http/Controllers/RecipeController.php

43 lines
1 KiB
PHP
Raw Normal View History

2022-11-18 12:39:03 +01:00
<?php
namespace App\Http\Controllers;
use App\Recipe;
class RecipeController extends Controller
{
/**
* Display a listing of the resource.
*
2022-12-23 17:24:09 +00:00
* @return \Illuminate\Contracts\View\View
2022-11-18 12:39:03 +01:00
*/
public function index()
{
2022-12-23 17:24:09 +00:00
// Get recipies.
2022-11-18 12:39:03 +01:00
$recipes = Recipe::where('live', '1')->get();
2022-12-23 17:24:09 +00:00
// Filter poultry.
2022-11-18 12:39:03 +01:00
$poultries = $recipes->unique('cat')->pluck('cat');
2022-12-23 17:24:09 +00:00
// Filter difficulty.
2022-11-18 12:39:03 +01:00
$difficulties = $recipes->unique('difficulty')->pluck('difficulty');
2022-11-18 15:35:39 +01:00
return view('pages.rezepte', compact(['recipes', 'poultries', 'difficulties']));
2022-11-18 12:39:03 +01:00
}
2022-12-23 17:24:09 +00:00
/**
* Recipe show
*
* @param mixed $id
* @return \Illuminate\Contracts\View\View
*/
public function show(mixed $id)
2022-11-18 12:39:03 +01:00
{
$recipe = Recipe::where('id', $id)->first();
2022-11-18 15:35:39 +01:00
if ($recipe == null) {
2022-11-18 12:39:03 +01:00
$recipe = Recipe::where('slug', $id)->first();
2022-11-18 15:35:39 +01:00
if ($recipe == null) {
2022-11-18 12:39:03 +01:00
abort(404);
}
}
2022-11-18 15:35:39 +01:00
return view('pages.rezept', compact(['recipe']));
}
2022-11-18 12:39:03 +01:00
}