PHP code example of omaressaouaf / query-builder-criteria
1. Go to this page and download the library: Download omaressaouaf/query-builder-criteria 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/ */
omaressaouaf / query-builder-criteria example snippets
return [
/**
* The name of the search_query_parameter inside the query string
* For example: GET /users?search_query=john
*/
'search_query_parameter' => 'search_query',
/**
* Split the search query into an array of terms to compare to
* This is applied for all criteria unless overridden inside the criteria class
*/
'split_search_into_terms' => false,
/**
* Define a default sorts for all criteria
* This is applied for all criteria unless overridden inside the criteria class
*
* Possible value types: array, string, null
*/
'default_sorts' => null,
];
namespace App\Criteria;
use Omaressaouaf\QueryBuilderCriteria\Criteria as BaseCriteria;
class PostCriteria extends BaseCriteria
{
protected array $filters = ['title'];
protected array $exactFilters = ['id', 'slug'];
protected array $sorts = ['published_at'];
protected array $
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Omaressaouaf\QueryBuilderCriteria\QueryableByCriteria;
use Omaressaouaf\QueryBuilderCriteria\Tests\Criteria\PostCriteria;
class Post extends Model
{
use QueryableByCriteria;
protected function defaultQueryBuilderCriteria(): array|string
{
return PostCriteria::class;
}
}
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\AllowedSort;
use Spatie\QueryBuilder\AllowedInclude;
protected function advancedFilters(): array
{
return [
AllowedFilter::callback('cb_filter_1', fn () => ''),
];
}
protected function advancedDefaultSorts(): array
{
return [
AllowedSort::callback('cb_sort_1', fn () => ''),
];
}
protected function advancedSorts(): array
{
return [
AllowedSort::callback('cb_sort_1', fn () => ''),
];
}
protected function advancedIncludes(): array
{
return [
AllowedInclude::callback('cb_
namespace App\Models\Models;
use Illuminate\Database\Eloquent\Model;
use Omaressaouaf\QueryBuilderCriteria\QueryableByCriteria;
use App\Criteria\PostCriteria;
class Post extends Model
{
use QueryableByCriteria;
protected function defaultQueryBuilderCriteria(): array|string
{
return PostCriteria::class;
}
}