What are query scopes?

Technology CommunityCategory: LaravelWhat are query scopes?
VietMX Staff asked 3 years ago

Local scopes allow you to define common sets of constraints that you may easily re-use throughout your application.

public function scopePopular($query)
{
    return $query->where('votes', '>', 100);
}

Consider:

$users = App\User::popular()->active()->orderBy('created_at')->get();