dinkbit / filterable by joecohens

Make your eloquent models filterable with ease.
34
7
9
Package Data
Maintainer Username: joecohens
Maintainer Contact: joseph.cohen@dinkbit.com (Joseph Cohen)
Package Create Date: 2015-02-17
Package Last Update: 2015-02-28
Language: PHP
License: MIT
Last Refreshed: 2024-11-15 15:09:33
Package Statistics
Total Downloads: 34
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 7
Total Watchers: 9
Total Forks: 0
Total Open Issues: 0

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