generated from boboko/starter
32 lines
792 B
PHP
32 lines
792 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Catalog\ProductListing;
|
|
use App\Catalog\ProductListingPage;
|
|
|
|
class SearchController extends Controller
|
|
{
|
|
public function __construct(private readonly ProductListingPage $listingPage) {}
|
|
|
|
public function show(string $locale)
|
|
{
|
|
$query = trim((string) request()->query('q', ''));
|
|
|
|
if ($query === '') {
|
|
return redirect()->route('products');
|
|
}
|
|
|
|
$listing = ProductListing::fromRequest(request());
|
|
|
|
$data = $this->listingPage->build(
|
|
$listing,
|
|
fn (array $overrides) => route('search', ['q' => $query] + $overrides),
|
|
collectionId: null,
|
|
query: $query,
|
|
);
|
|
|
|
return view('search.index', [...$data, 'query' => $query]);
|
|
}
|
|
}
|