这篇文章给大家介绍的内容是关于laravel中路由的代码实例介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
路由简介
请求转化给程序
作用:url和程序之间的映射
请求方式post get put patch delete
eg:
//get请求
Route::get('basic1',function(){
return 'hello world';
});
//多种请求
//指定请求方式
Route::match(['get','post'],'match',function(){
return 'match';
});
//不指定
Route::any('any',function(){
return 'any';
});
//路由参数
Route::get('user/{id}',function($id){
return 'User-'.$id;
});
Route::get('user/{id?}/{name?}',function($id,$name){
return 'User-name-'.$name;
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);
//请求的路由 http://localhost/public/user/1/w//路由的别名
Route::get('user/member-center',['as'=>'center',function(){
return route('center');
}]);
//路由群组
//prefix 前缀
Route::group(['prefix'=>'member'],function(){
Route::get('user/center',['as'=>'center',function(){
return route('center');
}]);
Route::get('user/person',['as'=>'person',function(){
return route('person');
}]);
});
//路由中输出view
Route::get('view', function () {
return view('welcome');
});以上就是本篇文章的全部内容了。
相关推荐:
laravel5.5框架中视图间如何共享数据?视图间共享数据的两种方法(附代码)
以上就是laravel中路由的代码实例介绍的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号