Split and Organise Laravel Routes into Multiple Files

If you are working with a huge Laravel project, at some point you will have a bloated web.php or api.php file with lots of routes, Although this works fine, but you may want to organize your route files better by splitting the routes of separate concerns into their individual file.

Here is the simplest way I have found in which you can organize / split your route file entries.

If you want a separate prefix for the route files which are in another file.


//web.php file
Route::prefix('/admin')->group(__DIR__.'/web/adminRoutes.php');

// routes/web/adminRoutes.php
Route::get('client/send', 'AdminControllerController@clientShow');
Route::post('client/send', 'AdminController@clientSend');

If you don’t want a route prefix, you can can pass an empty array as first parameter to the group method itself.

Livewire Component Library

//web.php file
Route::group([], __DIR__.'/web/adminRoutes.php');

// routes/web/adminRoutes.php
Route::get('client/send', 'AdminControllerController@clientShow');
Route::post('client/send', 'AdminController@clientSend');

Site Footer