krenor/eloquent-filter
最新稳定版本:1.0.0
Composer 安装命令:
composer require krenor/eloquent-filter
包简介
Filtering Laravel Eloquent queries with ease!
README 文档
README
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.
namespace App\Http\Models; use Illuminate\Database\Eloquent\Model; use Krenor\EloquentFilter\FilterableTrait; class Order extends Model { use FilterableTrait; ... }
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
protected $filterable = [ // column name => column alias 'status_id' => ['status' => [ // value aliases in database => input value 1 => 'pending', 2 => 'processing', 3 => 'completed' ] ]
-
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
统计信息
- 总下载量: 46
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-09