Laravel框架路由管理简单示例

(编辑:jimmy 日期: 2025/7/3 浏览:2)

本文实例讲述了Laravel框架路由管理。分享给大家供大家参考,具体如下:

路由中输出视图

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

get路由请求

Route::get('get',function(){
  return 'get路由请求';
});

post路由请求

Route::post('post',function(){
  return 'post请求';
});

多路由请求

Route::match(['get','post'],'match',function(){
  return '多路由请求';
});

任意路由请求

Route::any('any',function(){
  return '任意路由请求';
});

路由参数

Route::get('user/{id}',function($id){
  return 'user-id-'.$id;
});

路由参数默认值

Route::get('user/{name"htmlcode">
Route::get('user/{id}/{name"htmlcode">
Route::get('user/member-center',['as'=>'center',function(){
  return route('center');
}]);

路由群组

Route::group(['prefix'=>'member'],function(){
  //路由别名
  Route::get('user/member-center',['as'=>'center',function(){
    return route('center');
  }]);
  //任意路由请求
  Route::any('any',function(){
    return '任意路由请求';
  });
});

路由中输出视图

Route::get('view',function(){
  return view('welcome');
});

关联控制器

Route::get('member/info','MemberController@info');
Route::get('test','UserController@test');
Route::get('query','UserController@query');
Route::get('orm','UserController@orm');
Route::get('section1',['uses'=>'UserController@section1']);
Route::get('url',['as'=>'url','uses'=>'UserController@urlTest']);

更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。

一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。