Search code examples
laravelroutessubdomaininertiajs

Adding subdomain in Laravel 9


For some reason adding subdomain route isn't working and keeps on returning my homepage instead of the page I need. I'm using Laravel, Inertiajs Vue in my app.

Here is my route:

Route::domain('webshopview.localhost:8000')->group(function () {
    Route::get('/webshopview', function () {
        return Inertia::render('Products/Index');
    });
});

I want to be able to access it as webshopview.localhost:8000 but every time I try to visit this route it returns my app home page. If I do this in normal route like the below example, it works like a charm.

Route::get('/webshopview', function () {
    return Inertia::render('Products/Index');
});

What is missing to create a subdomain for group of routes? Why it keeps returning the app homepage ignoring the subdomain

My app works locally on 'http://localhost:8000/' and 'http://127.0.0.1:8000/' and it works like that by default without me doing anything. So all I want is to add subdomain to specific routes so that I can access like this 'example.localhost:8000' or 'example.127.0.0.1:8000'. The end result is to have the route displayed like this after deployment 'https://www.subdomain.domain.com'

I even tried this and it didn't work:

Route::get('/productview', function () {
    return 'First sub domain';
})->domain('productview.localhost');

now accessing 'http://productview.localhost/' returns 'This site can’t be reached' error.


Solution

  • I had to manually add the routes in my etc/hosts file on windows and restart the entire machine for it to take effect.