When defining a filter on a relation it would be great to also define which filter function to use. Currently the filter function on the related model has to be the same as the filter attribute on the original model. For example: I have a user model with a name filter. I have an issue model that has an author and an assignee. Currently I would have to write
class UserFilter extends ModelFilter
{
public function name(string $name)
{
foreach (explode(' ', $name) as $part) {
$this->where(function ($query) use ($part) {
$query->where('first_name', 'LIKE', '%' . $part . '%')
->orWhere('last_name', 'LIKE', '%' . $part . '%');
});
}
return $this;
}
public function authorName(string $name)
{
return $this->name($name);
}
public function assigneeName(string $name)
{
return $this->name($name);
}
}
class IssueFilter extends ModelFilter
{
public $relations = ['author' => ['author_name'], 'assignee' => ['assignee_name']];
}
It would be great If I could just do:
class IssueFilter extends ModelFilter
{
public $relations = ['author' => ['author_name' => 'name'], 'assignee' => ['assignee_name' => 'name']];
}
So when I filter by author_name on the issue model, I filter by the name-attribute on the author relation.
When defining a filter on a relation it would be great to also define which filter function to use. Currently the filter function on the related model has to be the same as the filter attribute on the original model. For example: I have a user model with a name filter. I have an issue model that has an author and an assignee. Currently I would have to write
It would be great If I could just do:
So when I filter by
author_name
on the issue model, I filter by thename
-attribute on the author relation.