PHP code example of alifcoder / query-filter

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

    

alifcoder / query-filter example snippets


// app/Filters/StatusFilter.php
use Alif\QueryFilter\Contracts\Filter;

class StatusFilter implements Filter
{
    public function handle(Builder $query, $value, Closure $next)
    {
        if ($value) {
            $query->where('status', $value);
        }

        return $next($query);
    }
}

use Alif\QueryFilter\QueryFilter;

$filtered = Post::filter(QueryFilter::make([
    'status' => request('status'),
    'sort' => request('sort'),
]))->get();

src/
├── Contracts/
│   └── Filter.php
├── Filters/
│   └── QueryFilter.php
├── QueryFilterServiceProvider.php
config/
└── query-filter.php