initial commit
This commit is contained in:
commit
ae93c7e1a6
233 changed files with 20282 additions and 0 deletions
26
backend/app/Http/Controllers/SearchController.php
Normal file
26
backend/app/Http/Controllers/SearchController.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SearchController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$queryString = $request->query('q');
|
||||
$page = $request->query('page', 1);
|
||||
|
||||
$query = Product::query()
|
||||
->active();
|
||||
|
||||
if (strlen($queryString) > 0) {
|
||||
$query->whereLike('name', '%' . $queryString . '%');
|
||||
}
|
||||
|
||||
return $query
|
||||
->paginate(10, ['*'], 'page', $page)
|
||||
->toResourceCollection();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue