Laravel 学习(一) 路由

useApp\Task;

useIlluminate\Http\Request;

* 显示所有任务

*/Route::get('/',function(){//});/**

* 增加新的任务

*/Route::post('/task',function(Request$request){//});/**

* 删除一个已有的任务

*/Route::delete('/task/{id}',function($id){//});

Route::get('/', function () {

return view('welcome'); //视图

});

//基础路由

Route::get('22',function(){

return '2222';

});

Route::post('22',function(){

return '2222';

});

//多请求路由

Route::any('e',function(){

return view('e');

});

Route::match(['get','post'],'m',function(){

return 'math';

});

//基础路由参数

Route::get('user/{id}',function($id){

return $id;

});

Route::get('user/{name?}',function($name='sss'){

return 'username'.$name;

});

Route::get('user/{name?}',function($name='sss'){

return 'username'.$name;

})->where('name','[A-Za-z]+');

Route::get('user/{name?}/{id}',function($name='sss'){

return 'username'.$name;

})->where(['name','[A-Za-z]+','id','[0-9]']);

//路由别名

Route::get('usera',['as' =>'center',function(){

return route('center');

}]);

//路由群组

Route::group(['prefix'=>'myi'],function (){

Route::get('my/{name?}',function($name='sss'){

return 'group->username->'.$name;

});

});

你可能感兴趣的:(Laravel 学习(一) 路由)