There are many ways using which you can group your routes in Laravel right now. Consider the following group of routes. use Illuminate\Support\Facades\Route; Route::get('/', [BookController::class, 'index']); Route::get('/books/{id}', [BookController::class, 'show']); Route::get('/books/search/{search}', [BookController::class, 'search']); Route::post('/book', [BookController::class, 'store']); As you can tell, we have four routes to manage books and if you notice, all of these routes have one thing in common.

use Illuminate\Support\Facades\Route; use App\Http\Controllers\BookController; Route::controller(BookController::class)->group(function () { Route::get('/', 'index'); Route::get('/books/{id}', 'show'); Route::get('/books/search/{search}', 'search'); Route::post('/book', 'store'); }); As you can tell, by using this approach now you have all the routes, that use the same controller, are under the same group.

Now, if you’re grouping routes by controllers using the above approach and if you specify the controller on the route once again, it will override the group controller.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners