Laravel 9 中的新功能: Route::controller ()
laravel 9新增了很多新功能,下面要讲的这个功能就是其中之一。
如果你的 Controller 中有一些方法,但它们不遵循标准的 Resource 结构,您仍然可以对它们进行分组,而无需为每个方法重复 Controller 名称。
取而代之的是:
Route::get('profile', [ProfileController::class, 'getProfile']);
Route::put('profile', [ProfileController::class, 'updateProfile']);
Route::delete('profile', [ProfileController::class, 'deleteProfile']);
您可以这样做:
Route::controller(ProfileController::class)->group(function() {
Route::get('profile', 'getProfile');
Route::put('profile', 'updateProfile');
Route::delete('profile', 'deleteProfile');
});
此功能在 Laravel 9 和 Laravel 8 的最新小版本中可用。
f4011412-a813-01b3-0d44-b5cc215f5032
本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 (CC BY-NC-ND 4.0) 进行许可。