Download the PHP package bahram/bfilters without Composer
On this page you can find all versions of the php package bahram/bfilters. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bahram/bfilters
More information about bahram/bfilters
Files in bahram/bfilters
Package bfilters
Short Description A package for customized filtering on eloquent models
License MIT
Informations about the package bfilters
Bahram Filter
Apply auto filters to Eloquent models.
Using this package, easily apply filters, sorting and pagination to Eloquent models and their relations, with query string parameters.
Requirements
php: ^8.0|^8.1
laravel: >=8.0
For miner php|Laravel versions use other releases.
Installation
Use HasFilter Trait On your Eloquent Models
Your models should use the HasFilter
trait:
Create Filter Class
for example:
In your Created Filter Class :
Usage
In controllers :
In Api Request Query String :
Add Validation Rules
To validate filters before applying it, add this method to your filter class:
If you need custom filter on relation : (For example array search in postgresql) :
In Request
Json Search:
Assume you have a json column named address like this :
So you Can simply add Your Json Column(s) to your filter class, like this:
Then you can apply filters on your Model as simple as this :
filter:{"filters":[[{"field":"city_name","op":"=","value":"tehran"}],[{"field":"street_name","op":"=","value":"jordan"}]]}
Query String Samples:
pagination: per_page=10 :
?filter={"page":{"limit": 10,"offset": 0}}
pagination per_page=20 and (ordered by id
desc) :
?filter={"page":{"limit":20,"offset":0},"sort":[{"field":"id","dir":"desc"}]}
add a filter : name like john :
?filter={"page":{"limit":20,"offset":0},"sort":[{"field":"id","dir":"desc"}],"filters":[[{"field":"name","op":"like","value":"john"}]]}
(first_name like alireza or
last name like bahram) and
(email = [email protected])
you can use magic filters
as well:
without using field
,op
, and value
(email = [email protected]):
full Text Search:
Basic Methods
Use Make Filter class to make a custom filter on an Api call
For example assume a function within your controller:
Edit given request filters
"addMagicFilter" method
"addOrder" method
use "setFilters" method to set multiple filters
use "getFilters" method to get the applied filters as an array
use "getFilter" method to get a specific filter
use "setWiths" method to eager loads some specific relations of the model
use "getWiths" method to get relations already set on given filters
use "setPage" method to set pagination on filters
use "getPage" method to get pagination already applied to the given request
All versions of bfilters with dependencies
ext-json Version *