Home  >  Article  >  Backend Development  >  The use of named routes in laravel

The use of named routes in laravel

高洛峰
高洛峰Original
2017-03-24 15:11:541811browse

This article mainly introduces how to use named routing in laravel. Friends in need can refer to it. Let’s take a look together.

The use of named routes in laravel

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(&#39;web.user&#39;)}}" 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

A note about Laravel Route redirection

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