indexzer0/eloquent-filtering
Filter Laravel Eloquent models using simple arrays and request data—no custom query spaghetti. Define allowed filters on your models, support complex search, and keep queries readable, maintainable, and easy to extend for APIs and dashboards.
Modifiers are ways to slightly alter the way that a filter works.
Append :{modifierName} to the type of the filter.
$filter = [
'type' => '$like:start',
'target' => 'framework',
'value' => 'laravel',
];
Multiple modifiers can be applied.
$filter = [
'type' => '$like:start:end',
'target' => 'framework',
'value' => 'laravel',
];
Some of the core filters provided by this package have modifiers.
$like <Icon icon="link" iconType="solid" />
:start - matches only the start of field LIKE 'Laravel%'.:end - matches only the end of field LIKE '%Laravel'.$notLike <Icon icon="link" iconType="solid" />
:start - matches only the start of field NOT LIKE 'Laravel%'.:end - matches only the end of field NOT LIKE '%Laravel'.$in <Icon icon="link" iconType="solid" />
:null - also does a or "{$target}" is null.$notIn <Icon icon="link" iconType="solid" />
:null- also does a and "{$target}" is not null.By default, all filter modifiers are enabled.
Though, you can specify only specific modifiers to enable.
public function allowedFilters(): AllowedFilterList
{
return Filter::only(
Filter::field('name', [FilterType::LIKE->withModifiers('end')])
);
}
You can also disable all modifiers.
public function allowedFilters(): AllowedFilterList
{
return Filter::only(
Filter::field('name', [FilterType::LIKE->withoutModifiers()])
);
}
How can I help you explore Laravel packages today?