码迷,mamicode.com
首页 > 其他好文 > 详细

laravel -- 路由

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

标签:member   function   路由   post   mem   any   match   welcome   fun   

基本路由

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

标签:member   function   路由   post   mem   any   match   welcome   fun   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!