ldc-doux/app/Http/Controllers/ProductsController.php

40 lines
1.1 KiB
PHP
Raw Normal View History

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;
use Illuminate\Http\Request;
2021-12-22 17:32:05 +01:00
class ProductsController extends Controller
{
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
2021-12-22 17:32:05 +01:00
public function show(Gamme $gamme, Product $product)
{
2022-05-12 16:03:40 +02:00
$seoDatum = new SeoDatum();
$seoDatum->title = $product->name;
$seoDatum->description = $product->description;
return view('front.product', compact('product', 'gamme', 'seoDatum'));
2021-12-22 17:32:05 +01:00
}
2022-07-27 14:33:56 +02:00
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'));
}
2021-12-22 17:32:05 +01:00
}