استخدم النطاقات للاستعلامات القابلة لإعادة الاستخدام:
النطاقات المحلية
public function scopePopular($query)
{
return $query->where('views', '>', 1000);
}استخدام النطاقات
$posts = Post::popular()->published()->get();النطاقات الديناميكية
public function scopeOfType($query, $type)
{
return $query->where('type', $type);
}النطاقات العامة
class ActiveScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
$builder->where('active', 1);
}
}