1. Go to this page and download the library: Download 7amoood/eloquent-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/ */
7amoood / eloquent-filter example snippets
use Hamoood\EloquentFilter\HasFilter;
class Post extends Model
{
use HasFilter;
protected array $sortCols = ['created_at', 'title'];
protected array $filterSearchCols = ['title', 'body'];
protected array $filterCols = ['status', 'category_id'];
protected int $filterLimit = 50;
}
return [
// Request parameter key containing filter data
'request_key' => 'filter',
// Max rows when model has no $filterLimit (null to disable)
'default_limit' => 1000,
// Default sort direction
'default_sort_direction' => 'asc',
];
Post::query()->filter(key: 'f')->paginate();
// reads from ?f[search]=...