thesimons's avatar

Remove /api and implement api.domain in Laravel 12 API

Hello,

I'd like to move api to a dedicated subdomain. Currently I have the following in Routes/api.php

Route::domain(config('domains.api'))->group(function () {
    Route::post('/checkout/create', [CheckoutController::class, 'create'])->name('api.checkout.create');
});

For reference config('domains.api') is "linked" to config/domains.php

return [
    'app' => env('DOMAIN_APP', 'xxx.com'),
    'api' => env('DOMAIN_API', 'api.xxx.com'),
   //other code
];

Actually everything works with https://api.xxx.com/api/checkout/create. I'd like to use https://api.xxx.com/checkout/create.

Thanks, Simon

0 likes
2 replies
Glukinho's avatar
Level 31

https://laravel.com/docs/12.x/routing#api-routes

Additionally, the /api URI prefix is automatically applied to these routes, so you do not need to manually apply it to every route in the file. You may change the prefix by modifying your application's bootstrap/app.php file:

thesimons's avatar

Thanks! Found it myself but forgot to update this thread. Thanks a ton for the link :)

Please or to participate in this conversation.