1. Go to this page and download the library: Download hyvor/laravel-filterq 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/ */
class MyController {
public function handle(Request $request) {
$filter = $request->input('filter');
FilterQ::expression($expression)
->builder(Post::class)
// other methods...
}
}
FilterQ::expression(...)
->builder(...)
->keys(function($keys) {
// only these operators will be allowed (comma-separated string)
$keys->add('id')->operators('=,>,<');
// or use an array
$keys->add('slug')->operators(['=', '!=']);
// exclude operators (use true as the second param)
$keys->add('age')->operators('>', true);
})
->addWhere();
FilterQ::expression(...)
->builder(...)
->keys(function($keys) {
$keys->add('id')->valueType('integer');
$keys->add('name')->valueType('string');
$keys->add('description')->valueType('string|null'); // |-seperated types
$keys->add('title')->valueType(['string', 'null']); // or an array
$keys->add('created_at')->valueType('date');
});
$keys->add('created_at')->valueType('date|null');
// or
$keys->add('created_at')->valueType(['date', 'null']);
FilterQ::expression(...)
->builder(...)
->keys(function($keys) {
// allows either published or draft
$keys->add('status')->values(['published', 'draft']);
// only 200 is allowed
$keys->add('id')->values(200);
});