ldc-domaine-de-lanvaux/app/Http/Controllers/ProductsController.php

51 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2022-08-05 09:38:44 +00:00
<?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
{
2022-12-23 17:14:56 +01:00
$parent_gamme = Gamme::find($gamme->parent_gamme_id);
2022-08-05 09:38:44 +00:00
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 . '%')
2023-06-05 11:45:26 +02:00
->orderBy('order')
2022-08-05 09:38:44 +00:00
->get();
} else {
$products = Product::where('is_published', 1)
2023-06-05 11:45:26 +02:00
->orderBy('order')
2022-08-05 09:38:44 +00:00
->get();
}
$search_title = 'Recherche : ' . $filter;
return view('front.search', compact('products', 'search_title', 'filter'));
}
}