Home / Snippets / Laravel Wildcard Subdomain Routing
Laravel Wildcard Subdomain Routing cover

Laravel Wildcard Subdomain Routing

524

2 years ago

0 comments

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
notion avatar

Ahabz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this