laravel 数据库 3 -- scope
20 March 2017
use Illuminate\Database\Eloquent\Builder;

class User extends Model {
    public function scopePopular(Builder $query) {
        return $query->where('votes', '>', 100);
    }
}

// App\User::popular()->get();   # select xxx where votes > 100

class User extends Model{
    public function scopeOfType($query, $value) {
        return $query->where('type', $value);
    }
}

// $users = App\User::ofType('admin')->get();  # where type = admin