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

38 lines
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;
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)
{
//$product = Product::whereSlug($product->slug)->first();
//dd($product);
2021-12-22 17:32:05 +01:00
return view('front.product', compact('product', 'gamme'));
}
public function search(Request $request) {
$filter = $request->query('filter');
if (!empty($filter)) {
$products = Product::where('is_published', 1)
->where('name', 'like', '%' . $filter . '%')
->get();
//->paginate(12);
} else {
$products = Product::where('is_published', 1)
->get();
//->paginate(12);
}
$search_title = 'Recherche : ' . $filter;
return view('front.search', compact('products', 'search_title', 'filter'));
}
2021-12-22 17:32:05 +01:00
}