Static Call using Laravel Eloquent Query Scope
Part A: ( Introduction )
Local scopes allow you to define common sets of query constraints that you may easily re-use throughout your application. For example, you may need to frequently retrieve all users that are considered “popular”. To define a scope, prefix an Eloquent model method with
Scopes should always return a query builder instance.
Here you see a Laravel Model Scope
The usage will be:
Part B: Static Call to Laravel Scope
Instead of putting
get() method when retrieving those specific kind of users like above, we can put
get() in one of the definition of Laravel scope like below which complete the query.
And then use like this without ending
or if you don’t want the popular users and need only active users you can use like this:
Which seems to be a normal static call but to the Laravel eloquent query scope!