Tuesday, September 18, 2018

How to remove "api" Prefix from URL

For Laravel 5.5:wn vote
accepted
It's just prefix to differ your api routes from other routes. You can add something different from apito here.
In app\Providers\RouterServiceProvider change this function:
   /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
Remove prefixe line:
   /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }

No comments: