@devondahon API routes aren’t prefixed by default: https://github.com/laravel/laravel/blob/8.x/app/Providers/RouteServiceProvider.php#L41-L44
If you want a path prefix then yes, you’ll need to add it to the route group.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm registering API routes in a package service provider like this:
$this->loadRoutesFrom(__DIR__ . '/../routes/api.php');
But then, the api/ route prefix is not applied anymore to routes set in api.php, should I put the routes in:
Route::prefix('api')->group(function () {
...
}
Or do I have something misconfigured ?
@devondahon You can just use the Route facade as you can in a Laravel application proper:
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
class YourPackageServiceProvider extends ServiceProvider
{
public function boot()
{
Route::middleware('api')->prefix('api')->group(function () {
$this->loadRoutesFrom(__DIR__ . '/../routes/api.php');
});
}
}
Please or to participate in this conversation.