How to add Custom Route File in Laravel?

Admin   Laravel   164  2021-03-16 00:20:04

Hi Guys,

In this blog, You can create Custom laravel route file in your project. we will create you how to Custom route file in laravel. i will show step by step create custom route file in laravel.This is a very easy way to manage laravel custom route files in your projects.i will create different route files like user_route, customer_route.

I will give full example of laravel custom route file, the example.

Step:1

First of all, we need to realize the existing code. See there is a method named map(). Add new two method named mapUserRoutes() for & mapCustomerRoutes().

app/providers/RouteServiceProvider.php

 

/**

* Define the routes for the application.

*

* @return void

*/

public function map()

{

$this->mapApiRoutes();

$this->mapWebRoutes();

$this->mapCustomerRoutes();

$this->mapUserRoutes();

}

Step:2

In this method, two another method is called named mapCustomerRoutes() & mapUserRoutes(). If we want to see those two methods then we will that this method is mapping two individual route files named user.php & customer.php in the route folder.

app/providers/RouteServiceProvider.php

 

/**

* Define the "user" routes for the application.

*

* These routes are typically stateless.

*

* @return void

*/

protected function mapUserRoutes()

{

Route::middleware('web')

->namespace($this->namespace)

->group(base_path('routes/user.php'));

}

/**

* Define the "customer" routes for the application.

*

* These routes are typically stateless.

*

* @return void

*/

protected function mapCustomerRoutes()

{

Route::middleware('web')

->namespace($this->namespace)

->group(base_path('routes/customer.php'));

}

after, i will create the two file in routes folder user.php and customer.php.

Step:3

in this step, i will create custom route file get route. I will create route in user.php and customer.php

routes/user.php