Laravel subdomain routing is not working Laravel subdomain routing is not working laravel laravel

Laravel subdomain routing is not working


Laravel processes routes on a first-come-first-serve basis and therefore you need to place your least specific routes last in the routes file. This means that you need to place your route group above any other routes that have the same path.

For example, this will work as expected:

Route::group(['domain' => 'admin.localhost'], function () {    Route::get('/', function () {        return "This will respond to requests for 'admin.localhost/'";    });});Route::get('/', function () {    return "This will respond to all other '/' requests.";});

But this example will not:

Route::get('/', function () {    return "This will respond to all '/' requests before the route group gets processed.";});Route::group(['domain' => 'admin.localhost'], function () {    Route::get('/', function () {        return "This will never be called";    });});


Laravel's example...

Route::group(['domain' => '{account}.myapp.com'], function () {    Route::get('user/{id}', function ($account, $id) {        //    });});

Your code

Route::group(['domain' => 'admin.localhost'], function () {    Route::get('/', function () {        return view('welcome');    });});

If you look at the laravel example it gets the parameter $account in the route, this way we can route according to this variable. This can then be applied to the group or any route's in it..

That said, if it's not something driven by your database and you just want it with admin subdomain i would personally do this as a nginx config.

If you want to test nginx locally (easier) i personally recommended doing development with docker.

Hope this answers your question, if not let me know and ill try to answer for you.