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

39 lines
905 B
PHP
Raw Normal View History

2022-11-18 12:39:03 +01:00
<?php
namespace App\Http\Controllers;
use App\Product;
class ProductController extends Controller
{
2022-12-23 17:24:09 +00:00
/**
* Products index
*
* @return \Illuminate\Contracts\View\View
*/
2022-11-18 15:35:39 +01:00
public function index()
{
2022-12-23 17:24:09 +00:00
$products = Product::all()->sortby('sequence')->reverse()->groupBy('poultry');
2022-11-18 12:39:03 +01:00
$poultries = $products->keys()->sort();
return view('pages.produkte', compact(['products', 'poultries']));
}
2022-12-23 17:24:09 +00:00
/**
* Product show
*
* @param mixed $id
* @return \Illuminate\Contracts\View\View
*/
public function show(mixed $id)
2022-11-18 15:35:39 +01:00
{
2022-11-18 12:39:03 +01:00
$product = Product::where('id', $id)->first();
2022-11-18 15:35:39 +01:00
if ($product == null) {
2022-11-18 12:39:03 +01:00
$product = Product::where('slug', $id)->first();
2022-11-18 15:35:39 +01:00
if ($product == null) {
2022-11-18 12:39:03 +01:00
abort(404);
}
}
return view('pages.produkt', compact('product'));
}
}