I've got a VPS with IONOS (was 1&1) and running Plesk Obsidian and I am up to date using Laravel 9. Now I've hit a snag, all I want to do is add a simple subdomain :-
api.trolleyspotting.fun
So what would be https://trolleyspotting.fun/api/v1/trolleys/all
points to
https://api.trolleyspotting.fun/v1/trolleys/all
My issue is when I add the following code to routes/api.php
Route::domain('api.' . env('APP_URL'))->group(function() {
`Route::get('v1/trolleys/all', [ApiController:class, 'index']);`
});
And then go to https://api.trolleyspotting.fun/v1/trolleys/all
nothing happens! I added an A record for the subdomain in IONOS Domain control panel and it points to the VPS IP address. When I install the laravel application and try to do as above it just does not work. Where am I going wrong? It's added no problem on the Plesk side as a subdomain. Do I need to add something in routes/web.php
? I've tried just adding the A record for the subdomain and adding it to the DNS side on Plesk but not physically adding it as a subdomain with its own directories but that didn't work either. I am reaching the end of my patience because I'm not a novice and I have read up but no solutions on here or in tutorials (YouTube too) have worked.
Any advice or answers very much appreciated in advance.
Thanks!
CodePudding user response:
I would like to suggest you a simple and straight forward way to implement it.
- If you want to use sub-domain(like: api.xyz.com) map it from the subdomain management from hosting provider
- Point it to the public folder of your current laravel app deployment so it will work simple as api.xyz.com/api/{version}/{route_name}
i think you should follow this steps and you are good to go.