Download the PHP package krenor/eloquent-filter without Composer
On this page you can find all versions of the php package krenor/eloquent-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download krenor/eloquent-filter
More information about krenor/eloquent-filter
Files in krenor/eloquent-filter
Package eloquent-filter
Short Description Filtering Laravel Eloquent queries with ease!
License MIT
Informations about the package eloquent-filter
eloquent-filter
Simple and easy filtering an Eloquent Query of Laravel 5.1 with Inputs!
Installation
Step 1: Install Through Composer
Add to your root composer.json and install with composer install
or composer update
{
"require": {
"krenor/eloquent-filter": "~1.0.0"
}
}
or use composer require krenor/eloquent-filter
in your console.
Step 2: Import the Trait
In the Model you want to listen to Inputs, and automatically
filter them down by that input, just use and add the Trait.
Usage
Add a protected $filterable = []
to the Model using the Trait.
-
Column Names
- Correspond to the column name in the URL and filter down by that.
URL : /some_orders/all?status_id=2
protected $filterable = [ 'status_id' ]
- Correspond to the column name in the URL and filter down by that.
-
Aliases
-
Use an column alias instead for nice names.
URL : /some_orders/all?status=2
protected $filterable = [ 'status_id' => 'status' ]
- Add values aliases to a column alias.
URL : /some_orders/all?status=processing
-
Now each time you run a query like Order::with('relation1')->paginate()
the filter is automatically applied and checks for the Inputs in the URL.
Note that this package currently only supports the equal operator for filtering a query down.
Contributing
If you believe you have found an issue, please report it using the GitHub issue tracker,
or better yet, fork the repository and submit a pull request.
Licence
eloquent-filter is distributed under the terms of the MIT license