Relations Allowed Fields
Overview
By default, when specifying an Filter::relation()
or Filter::morphRelation()
, fields within that relationship are not included in the allowed filter list.
You can specify allowed filters inside a relation in two ways.
includeRelationFields()
Use ->includeRelationFields()
on Filter::relation()
or Filter::morphRelation()
.
This method instructs the package to look for AllowedField
filters within the allowedFilters()
method of the relation model.
The relationship method MUST have return type specified, and the related model MUST also implement IsFilterable
.
For Filter::morphRelation()
, you should specify the models for which to include the relation fields for.
Define allowedFilters
Alternatively, if you don’t want to use ->includeRelationFields()
, you can define allowedFilters
for each Filter::relation()
and Filter::morphType()
.