1.路由簡介
請求轉化給程序
作用: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');
});