Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 817 Bytes

README.md

File metadata and controls

39 lines (29 loc) · 817 Bytes

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