Download the PHP package hugorut/filterable without Composer
On this page you can find all versions of the php package hugorut/filterable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hugorut/filterable
More information about hugorut/filterable
Files in hugorut/filterable
Package filterable
Short Description A laravel package for working with query filtering
License MIT
Homepage https://github.com/hugorut/filterable
Informations about the package filterable
Fiterable
A package which provides a fluent interface to apply constraints to an Eloquent query
For example:
Installation
First, pull in the package through Composer.
Include the service provider within config/app.php
.
Add the facade alias to this same file at the bottom:
Then publish the package assets by running in your project root
You should see a terminal output similar to:
Usage
Config
First you need to provide the package with knowledge of what models are filterable and which can have filters applied to them. Add your settings to the package configuration file which located at app\config\filter.php
after you have published the package assets.
Add models you wish to apply filters to in the Builders array
Add models you wish to filter by in the Filters array
API
It is highly recommended that you use the Filter facade or dependency injection to access the package functionality as this the class has a number of depencies which the laravel IOC container can rectify.
Using the Filter class is simple, first set a model you wish to appy filters against (and which has been aliased in the filter config file).
Now the filter is configured to the correct model you can call either the only
or the without
methods on the filter.
The parameters of both of these methods are an assoicative array. The keys of this associative array are the model aliases (as defined in your app\config\filter.php
config file) and the values are an array of the ids of these models.
Call the get
method on the filter to then query the database and return the filtered results.