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-11-09 17:56:26 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();