Laravel multiple routes file for api Laravel multiple routes file for api laravel laravel

Laravel multiple routes file for api


  1. create two route files: admin.api.php and app.api.php.
  2. edit the RouteServiceProvider.php file as below:
    <?php    namespace App\Providers;    use Illuminate\Support\Facades\Route;    class RouteServiceProvider extends ServiceProvider    {        protected $namespace = 'App\Http\Controllers';        protected $apiNamespace = 'App\Http\Controllers\Api\v1';        public function boot()        {            parent::boot();        }        public function map(Router $router) {            $router->group(['namespace' => $this->namespace], function ($router) {                require app_path('Http/routes/web.php');            });            $router->group(['namespace' => $this->apiNamespace], function ($router) {                require app_path('Http/api.php');            });            $router->group(['namespace' => $this->apiNamespace], function ($router) {                require app_path('Http/admin.api.php');            });        }    }

For more detail see here.