DEV Community

DowarDev
DowarDev

Posted on

Create multiple files for your routes in Laravel

While adding functionalities to my website, the need arose to better organize my routes in separate files, and for this reason I began to investigate how it is done and what I come to share with you today.

It is a very simple task since you will only have to make the modifications to the file
app / Providers / RouteServiceProvider.php in the mapWebRoutes function by adding require base_path ('routes / filename.php');

Example:
We create a file called user.php that will contain the routes related to the users, now we simply register it in the mapWebRoutes function as follows require base_path ('routes / user.php'); finally leaving the function like this

protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(function ($router) {
require base_path('routes/usuario.php');
require base_path('routes/web.php');
});
}}

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay