Laravel中的路由管理

//路由中输出视图
Route::get('/', function () {
return view('welcome');
});

//get路由请求
Route::get('get',function(){
return 'get路由请求';
});

//post路由请求
Route::post('post',function(){
return 'post请求';
});

//多路由请求
Route::match(['get','post'],'match',function(){
return '多路由请求';
});

//任意路由请求
Route::any('any',function(){
return '任意路由请求';
});

//路由参数
Route::get('user/{id}',function($id){
return 'user-id-'.$id;
});

//路由参数默认值
Route::get('user/{name?}',function($name = 'yxh'){
return 'user-name-'.$name;
});

//路由参数的正则验证
Route::get('user/{id}/{name?}',function($id,$name = 'yxh'){
return 'user-id-'.$id.'-name-'.$name;
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);

//路由别名
Route::get('user/member-center',['as'=>'center',function(){
return route('center');
}]);

//路由群组
Route::group(['prefix'=>'member'],function(){
//路由别名
Route::get('user/member-center',['as'=>'center',function(){
return route('center');
}]);

//任意路由请求
Route::any('any',function(){
return '任意路由请求';
});
});

//路由中输出视图
Route::get('view',function(){
return view('welcome');
});

//关联控制器
Route::get('member/info','MemberController@info');

Route::get('test','UserController@test');

Route::get('query','UserController@query');

Route::get('orm','UserController@orm');

Route::get('section1',['uses'=>'UserController@section1']);

Route::get('url',['as'=>'url','uses'=>'UserController@urlTest']);
原文地址:https://www.cnblogs.com/yxhblogs/p/5977936.html