Skip to content

How to Handle Subdomains in Laravel? #3

Discussion options

You must be logged in to vote

Laravel makes it easy to define routes for subdomains. Use the domain method in your routes/web.php file:

Route::domain('{subdomain}.example.com')->group(function () {
    Route::get('/', function ($subdomain) {
        return "Welcome to $subdomain!";
    });

    // Add additional routes here.
});

Key Points:

  • The {subdomain} parameter captures the subdomain part of the URL.
  • You can use the captured subdomain for dynamic content or logic.

This helps Laravel generate proper URLs for your application.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pasindu-kavinda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants