Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

StefanRusu's avatar

Laravel - Forge - Subdomains & Routing

Hi guys,

I have my app hosted on Digital Ocean. Server management is done through Forge. Now, I've created my subdomain & added the records.

What I want to do is have {subdomain}.name.com and have it return JSON like in the example below or....anything else.

The code below is what I see some people doing.

$domain = env('APP_URL');

Route::domain('admin.' . $domain)->group(function () {
    Route::get('test', function () {
        return response()->json([
            'ok' => true
        ]);
    });
});

I've tried with the RouteServiceProvider as well....no luck.

When I'm creating a new site in Forge I can add sub domains. So I've done just that - admin.example.com

When I do check the subdomain it shows the index.php with phpversion()

I don't know how to go about it anymore.

Thank you for your time.

0 likes
1 reply

Please or to participate in this conversation.