How to add multiple route file using RouteServiceProvider in laravel
Asked Answered
L

1

5

I want to create module wise route file and load all route files using RouteServiceProvider mapApiRoutes(). I have created category.php file and admin.php file which contains routes within it. Now i want to load this two file's routes in api.php file.

Below is code that i am using to do this but it is not working. it only process routes in admin.php. when i use route of category.php it shows me error of "Sorry, the page you are looking for could not be found.". Thank for help in advance.

protected function mapApiRoutes()
{
    Route::prefix('api')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(
                base_path('routes/admin.php'),
                base_path('routes/category.php'),
                base_path('routes/api.php')
              );
}
Lambent answered 5/10, 2018 at 10:4 Comment(0)
L
10

I have solved this issue by following code. Hope this will help someone.

protected function mapApiRoutes()
{
    Route::prefix('api')
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(function ($router) {
            require base_path('routes/admin.php');
            require base_path('routes/category.php');
        });

}
Lambent answered 5/10, 2018 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.