stobys/laravel-filterable
Composer 安装命令:
composer create-project stobys/laravel-filterable
包简介
The Laravel filterable trait.
README 文档
README
Filterable trait for Laravel models. Slightly inspired by n7olkachev/laravel-filterable.
Version: 1.0.1
How it works
In POST request, it looks for form fields defained in trait property filterable_fields and filter model by them.
If model has defained scope with name of form field it uses that scope.
One can use it in this way:
\App\User::filter()->get()
As for now, it can filer collection by three methods - exact filter (is), like filter (like) and range filter (between).
Installation
You can install the package via composer:
composer require stobys/laravel-filterable
Next, add Filterable trait and list all filterable properties:
use Filterable; protected $filterable_fields = [ 'id' => 'is', 'username' => 'like', 'created_at' => 'between', 'created_after' => 'scope' ];
And voila!
Examples
class User extends Model { use Filterable; protected $filterable_fields = [ 'id' => 'is', 'username' => 'like', 'created_at' => 'between', 'created_after' => 'scope' ]; public function scopeCreatedAfter($query, $time) { return $query->where('created_at', '>', $time); } }
License
The MIT License (MIT)
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-15