What is the scope in laravel routing?
Scope scope in laravel
In laravel, scope is introduced to handle data (belonging or not) in the template (add, delete, modify, check) Processing
is to add the prefix scope in the template definition method.
In short, the model in Laravel can define methods at the beginning of the scope, and these methods can be called directly through the model. This type of approach is also called query scope.
In laravel, it is required that the letters following the defined method scope must be capitalized
Then we go to the controller to process the template data
Used in the controller: remove the scope prefix, change the first letter to lower case and call it.
Regarding the parameter $query in the method, check the Api document to understand the scope definition The method has two parameters, one is Builder and the other is Model.
Add a scope prefix before the Post model method, and the scope will always be returned to the query builder. When calling the scope scope method, the returned builder is used to splice the complete query conditions.
For more Laravel related technical articles, please visit the Laravel Framework Getting Started Tutorial column to learn!
The above is the detailed content of What is scope in laravel routing?. For more information, please follow other related articles on the PHP Chinese website!