Laravel Mannequin Filter affords a easy strategy to filter and search eloquent fashions by array parameters and question strings.
This is a easy instance for instance precisely how this bundle works. Given the next filter, you’ll be able to generate with the offered make:filter
command:
namespace AppModelsFilters;
use LacodixLaravelModelFilterFiltersDateFilter;
class CreatedAfterFilter extends DateFilter
{
public FilterMode $mode = FilterMode::GREATER_OR_EQUAL;
protected string $area = 'created_at';
}
You’ll be able to apply the CreatedAfterFilter
on a mannequin like the next instance:
namespace AppModels;
use AppModelsFiltersCreatedAfterFilter;
use IlluminateDatabaseEloquentModel;
use LacodixLaravelModelFilterTraitsHasFilters;
class Submit extends Mannequin
{
use HasFilters;
protected array $filters = [
CreatedAfterFilter::class,
];
}
You’ll be able to then set off the filter both programmatically or through question string:
Submit::filter(['created_after_filter' => '2023-01-01'])->get();
// A number of filters
Submit::filter([
'created_after_filter' => '2023-01-01',
'published_filter' => true,
])->get();
// Or by question string: /posts?created_after_filter=2023-01-01
Submit::filterByQueryString()->get();
This bundle consists of many options associated to filtering fashions, reminiscent of:
- Group filtering
- Filter validation
- Sorting
- Looking
- Date filter kind
- String filter kind
- Choose filter kind
- Numeric filter kind
- Boolean filter kind
- Trashed filter kind
- Filtering on relations
- And extra
To get began with this bundle, take a look at the official documentation; the supply code can also be on GitHub at lacodix/laravel-model-filter.