Home >Backend Development >PHP Tutorial >The use of named routes in laravel
This article mainly introduces how to use named routing in laravel. Friends in need can refer to it. Let’s take a look together.
Laravel provides many magic methods. Let’s first talk about the use of named routes. There are two methods that are very convenient.
Named routing allows you to more conveniently generate URLs or redirects for specific routes. You can use the as array key to specify the name to the route
1. Type 1: Implement it through the as keyword in the route
Route::get('api/user',['as'='web.user'],'messageController@userInformation');
2. The second type: implement named routing through Route’s magic method name
Route::get('api/user','messageController@userInformation')->name('web.user');
3. How to use
in code You can use it like this
this->visit(route('web.user'))
Use it like this in the template
<a href="{{route('web.user')}}" rel="external nofollow" >user</a>
For more articles related to the use of named routes in laravel, please pay attention to the PHP Chinese website!
Related articles:
In the Laravel framework, what is the difference between {{url}} and {{asset}}?
##Explore The problem that Laravel uses the env function to read the environment variable is null