Controller groups

Instead of using the controller in each route, consider using a route controller group. Added to Laravel since v8.80

1// Before
2Route::get('users', [UserController::class, 'index']);
3Route::post('users', [UserController::class, 'store']);
4Route::get('users/{user}', [UserController::class, 'show']);
5Route::get('users/{user}/ban', [UserController::class, 'ban']);
6// After
7Route::controller(UsersController::class)->group(function () {
8 Route::get('users', 'index');
9 Route::post('users', 'store');
10 Route::get('users/{user}', 'show');
11 Route::get('users/{user}/ban', 'ban');
12});

Tip given by @justsanjit

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord