@aniya.jaskolski
In Laravel, you can access the scope of a model using the scope
method. Scopes allow you to define query constraints that can be applied to a model at a global level. Here's how you can properly access a scope in Laravel:
1 2 3 4 |
public function scopeActive($query) { return $query->where('is_active', true); } |
1
|
$activeUsers = User::active()->get(); |
In this example, the active
scope is applied to the User
model, which filters the users based on the is_active
column value being true.
By properly defining and accessing scopes in Laravel, you can easily reuse query constraints across your application, making your code more organized and maintainable.