krenor/eloquent-filter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

krenor/eloquent-filter

最新稳定版本:1.0.0

Composer 安装命令:

composer require krenor/eloquent-filter

包简介

Filtering Laravel Eloquent queries with ease!

README 文档

README

Latest Stable Version License

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.

  1. 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' ]
  2. Aliases

    1. Use an column alias instead for nice names.
      URL : /some_orders/all?status=2
      protected $filterable = [ 'status_id' => 'status' ]

    2. 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

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-09