I currently use global search in almost all my tables. I was looking for a way to improve the example documentation and would like to collaborate with other users on a possible cleaner option.
Currently according to the documentation you can do this:
$globalSearch = AllowedFilter::callback('global', function ($query, $value) {
$query->where(function ($query) use ($value) {
Collection::wrap($value)->each(function ($value) use ($query) {
$query
->orWhere('name', 'LIKE', "%{$value}%")
->orWhere('email', 'LIKE', "%{$value}%");
});
});
});
I am not a query builder expert so the filter could very possibly be optimised. Any suggestions would be appreciated.
I just wanted to share this idea with other users to improve the implementation of this table feature. Maybe we could get an almost perfect global filter class that could be included in the package itself.
Hello,
I currently use global search in almost all my tables. I was looking for a way to improve the example documentation and would like to collaborate with other users on a possible cleaner option.
Currently according to the documentation you can do this:
And use like:
This works fine, but does not allow you to search through relationships globally in a simple and clean way.
Instead of the above, you can create a custom filter class like this:
Then you can search through model columns and relationships with a few lines of code keeping your controller more cleaner:
I am not a query builder expert so the filter could very possibly be optimised. Any suggestions would be appreciated.
I just wanted to share this idea with other users to improve the implementation of this table feature. Maybe we could get an almost perfect global filter class that could be included in the package itself.