Home > Backend Development > PHP Tutorial > The use of named routes in laravel

The use of named routes in laravel

高洛峰
Release: 2023-03-06 07:02:01
Original
1858 people have browsed it

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');
Copy after login

2. The second type: implement named routing through Route’s magic method name

Route::get('api/user','messageController@userInformation')->name('web.user');
Copy after login

3. How to use

in code You can use it like this

this->visit(route('web.user'))
Copy after login

Use it like this in the template

<a href="{{route(&#39;web.user&#39;)}}" rel="external nofollow" >user</a>
Copy after login

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

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