首页 > 其他 > 详细

laravel -- 路由

时间:2018-07-16 22:02:16      阅读:150      评论:0      收藏:0      [点我收藏+]

基本路由

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 -- 路由

原文:https://www.cnblogs.com/yuexinyuya/p/9320652.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!