Laravel How to remove "api" Prefix from subdomain URL
It's just prefix to differ your api routes from other routes. You can add something different from api
to here.
In app\Providers\RouteServiceProvider
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'));
}
Actually in Laravel 8, i just remove api from prefix in App/Providers/RouteServiceProvider.php
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
to
Route::prefix('/')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));