PHP code example of ekramhossain / laravel-query-filter
1. Go to this page and download the library: Download ekramhossain/laravel-query-filter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ekramhossain / laravel-query-filter example snippets
use App\Models\Product;
use EkramHossain\LaravelQueryFilter\Facades\Filter;
public function index(Request $request)
{
$products = Filter::query(Product::query())
->allowedFilters([
'name',
'status',
'price',
'created_at',
])
->allowedSorts([
'name',
'price',
'created_at',
])
->apply($request)
->paginate();
return response()->json($products);
}