基本路由:  

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

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

 

路由前缀:

Route::group(['prefix'=>'wechat'],function (){
    Route::get('/',function (){
        return 'wechat根目录';
    });
});

 

带参数的路由:

//必须带上参数
Route::get('/edit/{id}',function ($id){
});
//可以不带参数,但是必须有默认值
Route::get('/edit/{id?}',,function ($id=1){
});
//可以跟上where,使用正则去匹配参数
Route::get('/edit/{id}',function ($id){
})->where('id', '[0-9]+');
Route::get('user/{id}/{name}', function ($id, $name) {
})->where(['id' => '[0-9]+', 'name' => '[a-z]+']);

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
猜你喜欢
  • 2021-09-17
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-09-30
相关资源
相似解决方案