Restrict
Global Filters
purity validates allowed filters in the following order of priority:
Filters specified in the
filtersconfiguration in theconfigs/purity.phpfile.
// configs/purity.php
'filters' => [
EqualFilter::class,
InFilter::class,
],
Filters declared in the
$filtersvariable in the model.
// App\Models\Post
private array $filters = [
'$eq',
'$in',
];
// or
private array $filters = [
EqualFilter::class,
InFilter::class,
];Filters passed as an array to the
filterBy()function.
Restrict by Field
There are three available Methods for your convenience. They take priority respectively.
Method 1: Define restricted filters inside
$filterFieldsproperty, as shown below
The drawback here is that you have to define all the allowed fields, regardless of any restriction fields.
Method 2: Define them inside
$restrictedFiltersproperty
Method 3: Finally, you can set it on the Eloquent builder, which takes the highest priority (overwrite all the above options)
All field-restricted filter operations are respected to filters defined in $filter in the model. This means you are not allowed to restrict a field operation not permitted in restricted fields.
Last updated