Home > PHP Framework > Laravel > Three ways to generate url patterns in Laravel

Three ways to generate url patterns in Laravel

藏色散人
Release: 2021-06-07 09:10:29
forward
2862 people have browsed it

The following tutorial column of laravel will introduce to you three methods of generating url patterns in Laravel. I hope it will be helpful to friends in need!

Three ways to generate url patterns in Laravel

Laravel generates url pattern

1. Generate through url auxiliary function (routing)

    location.href = "{{url('main/index')}}";
location.href = "{{url::to('main/index')}}";
Copy after login

2. Generate

through aliases (route) The premise is to specify the alias when registering the route, for example: Route::get('main/index',['as' => 'main/index', ' mains' => 'MainController@index']);

location.href = "{{route('main/index')}}";
location.href = "{{URL::route('main/index')}}";
Copy after login

3. Generated through controller and method names (aliases cannot be specified for routes):

location.href =  "{{action('UserController@index',['id'=>1,'author'=>'admin'])}}";
location.href =  "{{URL::action('UserController@index',['id'=>1,'author'=>'admin'])}}";
Copy after login

Note: carried in 2 and 3 The parameters can be used in the controller using Request $request to receive

The above is the detailed content of Three ways to generate url patterns in Laravel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template