get: 能直接通过浏览器访问
Route::get(‘RouteName’, function(){ return xxx; });post: 不能直接通过浏览器访问 match: 多重路由
Route::match([‘get’,’post’],’RouteName’, function(){ return xxx; });any: 任何请求
Route::any(‘RouteName’, function(){ return xxx; });路由参数
Route::get('user/{id?}',function ($id = 0){ return 'user-id-'. $id; })->where(['id' => '[0-9]+' , 'name' => '[A-Za-z]+']); ?:参数可有可无 $id = 0:默认参数为0 连接'user-id-'和$id的是".",不是"," where: 控制参数的范围路由别名
Route::get('user/111', ['as'=>'center', function(){ return route('center'); }]);其中别名111可随意变换,不影响输出结果,route函数为输出对应的URL
路由群组
Route::group(['prefix' => 'pre'], function (){ Route::get('user/111', ['as'=>'center', function(){ return route('center'); }]); Route::match(['get','post'],'RouteName', function(){ return 'pre-RouteName'; }); });访问时,localhost/public/pre/user/111 localhost/public/pre/RouteName