50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Gamme;
|
|
use App\Models\Product;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ProductsController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @param Gamme $gamme
|
|
* @param Product $product
|
|
* @return \Illuminate\Contracts\View\View
|
|
* @ignore phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
|
|
*/
|
|
public function show(Gamme $gamme, Product $product): \Illuminate\Contracts\View\View
|
|
{
|
|
$parent_gamme = Gamme::find($gamme->parent_gamme_id);
|
|
return view('front.product', compact('product', 'gamme', 'parent_gamme'));
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function search(Request $request): \Illuminate\Contracts\View\View
|
|
{
|
|
$filter = $request->query('filter');
|
|
|
|
if (!empty($filter)) {
|
|
$products = Product::where('is_published', 1)
|
|
->where('name', 'like', '%' . $filter . '%')
|
|
->orderBy('order')
|
|
->get();
|
|
} else {
|
|
$products = Product::where('is_published', 1)
|
|
->orderBy('order')
|
|
->get();
|
|
}
|
|
|
|
$search_title = 'Recherche : ' . $filter;
|
|
|
|
return view('front.search', compact('products', 'search_title', 'filter'));
|
|
}
|
|
}
|