How to Split Laravel Routes : This is The Solution!

How to Split Laravel Routes. 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.

From Laravel, by default like this.
Contents
Routing
To define routes for your package, simply require
the routes file from within your package service provider’s boot
method. From within your routes file, you may use the Route
facade to register routes just as you would within a typical Laravel application:
/** * Perform post-registration booting of services. * * @return void */public function boot(){ if (! $this->app->routesAreCached()) { require __DIR__.'/../../routes.php'; }}
Best Simple Solution How to Split Laravel Routes
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.
Read More Articles:
Web.php
open Laravel routes in routes/web.php. We will see Laravel code like this:
//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');
Copy
If you don’t want a route prefix, you can can pass an empty array as first parameter to the group method itself.
//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');
Any problem you can contact me in the comment box or directly on my social networks.
You can find more content like this on my Globalizations website