laravel -- 路由
Posted yuexinyuya
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel -- 路由相关的知识,希望对你有一定的参考价值。
基本路由
1 Route::get(‘/get‘,function (){ 2 return "this is get"; 3 }); 4 5 Route::post(‘/post‘,function (){ 6 return "this is post"; 7 });
多请求路由
1 Route::match( [‘get‘,‘post‘], ‘/match‘, function (){ 2 return "this is match"; 3 });
4 Route::any(‘/any‘, function (){ 5 return "this is any"; 6 });
路由参数
1 Route::get(‘/id/{id}‘,function ($id){ 2 return "ID--".$id; 3 });
带参数路由,可设置默认值,也可以设置正则验证
1 Route::get(‘/username/{name?}‘,function ($name=‘force‘){ 2 return "Name--".$name; 3 })->where(["name"=>"[A-Za-z]+"]);
路由别名
1 Route::get(‘/username/alias‘,[‘as‘=>‘alias‘,function (){ 2 return route(‘alias‘); 3 }]);
路由群组
1 Route::group([‘prefix‘=>‘member‘], function (){ 2 Route::get(‘/get‘,function (){ 3 return "this is member-get"; 4 }); 5 6 Route::any(‘/any‘,function (){ 7 return "this is member-any"; 8 }); 9 });
返回视图
1 Route::get(‘/‘, function () { 2 return view(‘welcome‘); 3 });
以上是关于laravel -- 路由的主要内容,如果未能解决你的问题,请参考以下文章