基本路由
Route::get('/',function(){
? ? ?return view('welcome');
})
Route::post('/',function(){
return view('welcome');
})
Route::put('/',function(){
return view('welcome');
})
Route::delete('/',function(){
return view('welcome');
})
Route::options('/',function(){
return view('welcome');
})
Route::patch('/',function(){
return view('welcome');
})
Route::any('/',function(){
return view('welcome');
})
匹配方式
Route::match(['get','post'],'/',function(){
return view('welcome');
})
路由參數(shù)
一個(gè)參數(shù)
//url中的參數(shù)和function()中的參數(shù)名字可以不同
Route::get('user/{id}',function($id){
return 'User.'.$id;
}
二個(gè)參數(shù)
Route::get('user/{id}/post/{e}',function($id,$e){
return 'User.'.$id.$e;
}
url / 換成 _
Route::get('user_{id}',function($id){
return 'User.'.$id;
}
可選參數(shù)
對(duì)于有兩個(gè)路由參數(shù)一般最后一個(gè)可以使用可選參數(shù)
Route::get('user/{id?}',function($id='www'){
return 'User.'.$id;
})
參數(shù)規(guī)則(正則表達(dá)式)
Route::get('user/{id}/post/{e}',function($id,$e){
return 'User.'.$id.$e;
})->where(['id' =>'[0-9]+','e'=>'[a-zA-Z]+']);
路由別名
Route::get('/one',[ 'as' =>'one' ,function(){
return 'User.'
]});
route('one');