Posts Learn Components Snippets Categories Tags Tools About
/

Laravel Wildcard Subdomain Routing

Learn how to define wildcard sudomain routing in your Laravel application

Created on Aug 02, 2021

511 views

Laravel provides a way to create a wildcard subdomain by calling the "domain()" method of the Route class. Subdomains may be assigned route parameters just like route URIs, allowing you to capture a portion of the subdomain for usage in your route or controller. The subdomain may be specified by calling the domain method before defining the group:

Wildcard Subdomain Routing in Laravel
<?php

Route::domain('​{project}​.example.com')->group(function () {
    Route::get('posts/{slug}', function (​$project​, $slug) {
        dd($project, $slug);
    });
});

The final link will be as follows
http://subdomain.example.com/posts/your-post-slug

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for Laravel Wildcard Subdomain Routing

)