Home > PHP Framework > Laravel > body text

Three ways to generate url patterns in Laravel

藏色散人
Release: 2021-06-07 09:10:29
forward
2666 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:
source:csdn.net
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!