52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Gamme;
|
|
use App\Models\Product;
|
|
use App\Models\SeoDatum;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ProductsController extends Controller
|
|
{
|
|
/**
|
|
* Show one product
|
|
*
|
|
* @param Gamme $gamme
|
|
* @param Product $product
|
|
* @return \Illuminate\Contracts\View\View
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
*/
|
|
public function show(Gamme $gamme, Product $product)
|
|
{
|
|
$seoDatum = new SeoDatum();
|
|
$seoDatum->title = $product->name;
|
|
$seoDatum->description = $product->description;
|
|
|
|
return view('front.product', compact('product', 'gamme', 'seoDatum'));
|
|
}
|
|
|
|
/**
|
|
* Display a list of products resulting from search query
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function search(Request $request)
|
|
{
|
|
$filter = $request->query('filter');
|
|
|
|
if (!empty($filter)) {
|
|
$products = Product::where('is_published', 1)
|
|
->where('name', 'like', '%' . $filter . '%')
|
|
->get();
|
|
} else {
|
|
$products = Product::where('is_published', 1)
|
|
->get();
|
|
}
|
|
|
|
$search_title = 'Recherche : ' . $filter;
|
|
|
|
return view('front.search', compact('products', 'search_title', 'filter'));
|
|
}
|
|
}
|