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

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

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

Okay