Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

Laravel 8 working with subdomain routing but its not working, I'm little confused about this anyone can answer

By M.K. Verma · 2 May 2022

Laravel 8 working with subdomain routing but its not working, I'm little confused about this anyone can answer

I have a suggestion... why not pass the domain as a parameter the way you would an unknown, article id for example /article/{id}?

Try this:

Route::domain('{user}.xyz.com')->group(function () {
    Route::get('/posts', [PostsController::class, 'view'])->name('posts');
});

In our PostsController output the results...

class PostsController {
    public function view ($user){
        dd($user) //this will output the current user's subdomain name
    }
}

Let me know if it works out for you.