Basics
Make Model Filterable
Introduction
Basics
- Installation
- Make Model Filterable
- Filtering Models
- Allowing Filters
- Relationships
Available Filters
- Full Filter List
- Field Filters
- Relation Filters
- Morph Relation Filters
- Condition Filters
Digging Deeper
Basics
Make Model Filterable
- Implement
IsFilterable
interface. - Use
Filterable
trait. - Define
allowedFilters()
method.
use IndexZer0\EloquentFiltering\Contracts\IsFilterable;
use IndexZer0\EloquentFiltering\Filter\Traits\Filterable;
use IndexZer0\EloquentFiltering\Filter\Contracts\AllowedFilterList;
use IndexZer0\EloquentFiltering\Filter\Filterable\Filter;
use IndexZer0\EloquentFiltering\Filter\FilterType;
class Product extends Model implements IsFilterable
{
use Filterable;
public function allowedFilters(): AllowedFilterList
{
return Filter::only(
Filter::field('name', [FilterType::EQUAL]),
);
}
}