Posts Learn Components Snippets Categories Tags About
/

Laravel Wildcard Subdomain Routing

Learn how to define wildcard sudomain routing in your Laravel application

Created on Aug 02, 2021

19 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

Snippets by

PostSrc poster

PostSrc

Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for Laravel Wildcard Subdomain Routing

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets

More