dinkbit/filterable

Make your eloquent models filterable with ease.
34 6
Install
composer require dinkbit/filterable
PHP:>=5.4.0
License:MIT
Last Updated:Feb 28, 2015
Links: GitHub  ·  Packagist
Maintainer: joecohens

Filterable Eloquent Models

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();