Download the PHP package larasquad/filter without Composer
On this page you can find all versions of the php package larasquad/filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download larasquad/filter
More information about larasquad/filter
Files in larasquad/filter
Package filter
Short Description This package make it easy to filter any resource.
License MIT
Informations about the package filter
Larasquad Filter
This package allows you to filter resource based on a request in a simple way and makes you controller code clean.
Installation
You can install the package via composer:
Basic usage
Make a filter class and extend it by
or, you can generate it by
It will generate a filter class on you app\Filters directory.
Specify the $request
attributes which you want to filter in $filterable
array.
Note that, if you put an attribute on the $filberable
array which is not available in database column, in these case, you have to write a method on it.
Example,
In these case, from
and to
attribute are not exists in my database column but I have send the attributes via $request
, then I have to
specify the from
and to
method else it will get an error.
Now, inject the class in you controller method where you have injected the Request $request
class
Replace the Request $request
from your method with UserFilter $filter
It will automaticall initiate the Request $request
in it's parent constructor.
Now use the Filterable
trait in you model.
It's done. Now you can you the filter
method in your controller and pass the $filter
object in the method.
By default, It filters the model by using Laravel
default where
clause.
Here, $request
input name is used as column and $request
input value is used as search value
You can override the search query
by writing a method on your Filter Class
. You have to name it like the model
database column name or the camelCase
or snake_case
of it.
License
The MIT License (MIT)