2021-12-22 17:32:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Models\Gamme;
|
|
|
|
|
use App\Models\Product;
|
2022-05-12 16:03:40 +02:00
|
|
|
use App\Models\SeoDatum;
|
2022-01-25 16:39:00 +01:00
|
|
|
use Illuminate\Http\Request;
|
2021-12-22 17:32:05 +01:00
|
|
|
|
|
|
|
|
class ProductsController extends Controller
|
|
|
|
|
{
|
2022-08-29 17:23:10 +02:00
|
|
|
/**
|
|
|
|
|
* Show one product
|
|
|
|
|
*
|
|
|
|
|
* @param Gamme $gamme
|
|
|
|
|
* @param Product $product
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
|
|
|
*/
|
2021-12-22 17:32:05 +01:00
|
|
|
public function show(Gamme $gamme, Product $product)
|
|
|
|
|
{
|
2022-08-11 12:34:27 +02:00
|
|
|
$seoDatum = new SeoDatum();
|
|
|
|
|
$seoDatum->title = $product->name;
|
2022-05-12 16:03:40 +02:00
|
|
|
$seoDatum->description = $product->description;
|
|
|
|
|
|
|
|
|
|
return view('front.product', compact('product', 'gamme', 'seoDatum'));
|
2021-12-22 17:32:05 +01:00
|
|
|
}
|
2022-01-25 16:39:00 +01:00
|
|
|
|
2022-08-29 17:23:10 +02:00
|
|
|
/**
|
|
|
|
|
* Display a list of products resulting from search query
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
2022-07-27 14:33:56 +02:00
|
|
|
public function search(Request $request)
|
|
|
|
|
{
|
2022-01-25 16:39:00 +01:00
|
|
|
$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'));
|
|
|
|
|
}
|
2021-12-22 17:32:05 +01:00
|
|
|
}
|