PHP code example of jurager / filterable

1. Go to this page and download the library: Download jurager/filterable 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/ */

    

jurager / filterable example snippets


use Jurager\Filterable\Concerns\HasFilterable;

class Product extends Model
{
    use HasFilterable;

    protected array $filterable = [
        'sku'             => ['eq', 'like'],
        'price'           => ['gte', 'lte', 'between'],
        'status'          => ['eq', 'in'],
        'category.name'   => ['eq', 'like'],
        'is_active',
    ];

    protected array $sortable = ['id', 'sku', 'price', 'created_at'];
}

Product::query()
    ->filter(request()->query('filter', []))
    ->sort(request()->query('sort'))
    ->paginate();