Download the PHP package dmarte/filterable without Composer
On this page you can find all versions of the php package dmarte/filterable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dmarte/filterable
More information about dmarte/filterable
Files in dmarte/filterable
Package filterable
Short Description Easy to use package to filter Laravel Eloquent records.
License MIT
Informations about the package filterable
Filterable
A Laravel library to handle filters for Eloquent models or Scout database records with a single API.
- How it works
- Implementation
- Pagination
- Reserved query string parameters
- Limiting the Full-Text columns check
- Filterable queries
- Resource response
How it works
Filterable automatically will perform the required implementation to fetch records from an eloquent model. At first, will try to check if want to perform a Laravel Scout search, or a full eloquent model search.
It also supports Full text search.
Implementation
Pagination
Filterable package by default will return a collection of records, if you would like to get the paginator format you must include the query string paginator=true
in the request.
With ?paginator=false
response will be:
With ?paginator=true
response will be:
Reserved query string
parameters
In order to change the expected results in search, filterable check with params you have in your request.
Parameter | Default | Description | Example |
---|---|---|---|
with_trashed |
false | Allow to include deleted records in the result set. |
?with_trashed=true |
per_page |
15 | Determine the number or records to get in the query. | ?per_page=20 |
with |
null | An array or string with the list of model relations to include. |
with[]=relation1&with[]=relation2 |
search |
null | A string to activate the full-text search support. | ?search=John%sdoe |
paginator |
false | Enable or disable the paginator format in data response. |
Limiting the Full-Text columns check
By specifying the list of columns that should be full-text searchable you can globally search based on generic criterea.
Filterable queries
You could create your own logic for each column when you override the method filterableQueries
.
IMPORTANT
You must be sure to return an instance of Illuminate\Support\Collection
with each callback.
The filterable engine will check the "key" on the collection to match the request "key", then will expect each value should be a callback function that perform your desired query.
Here is an example
Resource response
You could change the resource class used as response using the function qualifiedResource
. With this static
function you return the path of your resource.
NOTE By default it will take the name of the model with the suffix
Resource
. Eg. for\App\Models\User
model will try to find\App\Http\Resources\UserResource
.
You can change this behavior overriding that function.
Filter by multiple models
Useful for global searches you could create a multi-model filter.