Skip to main content
Quick Tip

Controller groups

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

// Before
Route::get('users', [UserController::class, 'index']);
Route::post('users', [UserController::class, 'store']);
Route::get('users/{user}', [UserController::class, 'show']);
Route::get('users/{user}/ban', [UserController::class, 'ban']);
// After
Route::controller(UsersController::class)->group(function () {
Route::get('users', 'index');
Route::post('users', 'store');
Route::get('users/{user}', 'show');
Route::get('users/{user}/ban', 'ban');
});

Tip given by @justsanjit

Enjoyed This Tip?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses on Laravel Daily

[NEW] Next.js Basics for Laravel Developers

11 lessons
58 min

Testing in Laravel 13 For Beginners

26 lessons
1 h 41 min read

How to Build Laravel 13 API From Scratch

30 lessons
1 h 23 min

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.