dinkbit/filterable

Make your eloquent models filterable with ease.

dev-master / 1.0.x-dev 2015-02-28 18:37 UTC

This package is not auto-updated.

Last update: 2024-10-26 17:45:34 UTC


README

Build Status StyleCI

Setup

use Dinkbit\Filterable\FiterableTrait;

class Post extends Eloquent
{
    use FilterableTrait;

    /**
     * Enabled filterable scopes.
     *
     * @var string
     */
    protected $filterable = ['price', 'quantity'];

    public function scopePrice($query, $param)
    {
        return $query->where('price', $param);
    }

    public function scopeQuantity($query, $param)
    {
        return $query->where('item_quantity', $param);
    }
}

Usage

$posts = Post::filter(['quantity' => 10, 'price' => '100'])->get();