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

What is scope in laravel routing?

藏色散人
Release: 2019-08-07 11:30:41
Original
3476 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template