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


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

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

The final link will be as follows

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