Home >PHP Framework >Laravel >Introduction to code examples of routing in laravel
This article introduces to you the code examples of routing in laravel. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Introduction to routing
Convert the request to the program
Function: mapping between url and program
Request method post get put patch delete
eg:
//get请求 Route::get('basic1',function(){ return 'hello world'; }); //多种请求 //指定请求方式 Route::match(['get','post'],'match',function(){ return 'match'; }); //不指定 Route::any('any',function(){ return 'any'; }); //路由参数 Route::get('user/{id}',function($id){ return 'User-'.$id; }); Route::get('user/{id?}/{name?}',function($id,$name){ return 'User-name-'.$name; })->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']); //请求的路由 http://localhost/public/user/1/w
//路由的别名 Route::get('user/member-center',['as'=>'center',function(){ return route('center'); }]); //路由群组 //prefix 前缀 Route::group(['prefix'=>'member'],function(){ Route::get('user/center',['as'=>'center',function(){ return route('center'); }]); Route::get('user/person',['as'=>'person',function(){ return route('person'); }]); }); //路由中输出view Route::get('view', function () { return view('welcome'); });
The above is the entire content of this article.
Related recommendations:
How to customize the analysis of log behavior in Laravel5.5
The above is the detailed content of Introduction to code examples of routing in laravel. For more information, please follow other related articles on the PHP Chinese website!