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

Three ways to generate url patterns in Laravel

藏色散人
藏色散人forward
2021-06-03 15:56:422731browse

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')}}";

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')}}";

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'])}}";

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete