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 });
扫描二维码关注公众号,回复: 2189791 查看本文章

返回视图

1 Route::get('/', function () {
2     return view('welcome');
3 });

猜你喜欢

转载自www.cnblogs.com/yuexinyuya/p/9320652.html