Home  >  Article  >  PHP Framework  >  What is scope in laravel routing?

What is scope in laravel routing?

藏色散人
藏色散人Original
2019-08-07 11:30:413415browse

What is scope in laravel routing?

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.

What is scope in laravel routing?

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

What is scope in laravel routing?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn