Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

trifek's avatar

Wildcard in route

Hi, I have this route in my web.php:

Route::get('/firma/{slug}', 'CompanyController@company')->name('company');

It's work: name.com/firma/company-name.

I need add to to this route wildcard:

company-name.name.com

How can I make it in Laravel?

0 likes
35 replies
trifek's avatar

yes, but I need company-name + 'domain.com'. First login company and them my domain.

How can I write it in web.php / router?

Sinnbeck's avatar

@trifek I just tested with /firma/company-name.name.com in the url, and that works just fine as a slug. Give an actual example that doesnt work.

tykus's avatar

Do you want two wildcards in the same segment @trifek

Route::get('/firma/{company_name}.{domain}', 'CompanyController@company')->name('company');
// CompanyController
public function company($company_name, $domain)
{
		//...
}
trifek's avatar

@tykus It's not working. When I have https://firma-2.domain.com - it's not working. https://domain.com/firma/firma-2 - this working fine

I have route:

Route::get('/firma/{slug}', 'CompanyController@company')->name('company');
Route::get('{company_name}.{domain}', 'CompanyController@company2')->name('company2');

and php:

public function company(string $slug)
public function company2($company_name, $domain)
tykus's avatar

@trifek you are describing sub-domain routing - sorry, this was not obvious from your earlier messages

tykus's avatar

@trifek like the docs say...

Route::domain('{company}.name.com')->group(function () {
    Route::get('/', function ($company) {
        //
    });
});
1 like
trifek's avatar

@MichalOravec yes, I try:

Route::get('/firma/{slug}', 'CompanyController@company')->name('company');

Route::domain('{slug}.domain.com')->group(function () {
    Route::get('/firma/{slug}', 'CompanyController@company')->name('company2');
});

but it's not working :(

tykus's avatar

@trifek I don't know what you mean by "main page"

In any case, the route you have defined would respond to https://firma-2.domain.com/firma/firma-2 because this is the route you defined inside the sub-domain group:

Route::get('/firma/{slug}', 'CompanyController@company')->name('company2');
tykus's avatar

@trifek in that case; two routes defined which are mapped to the same Controller / action

Route::get('/firma/{slug}', 'CompanyController@company')->name('company');

Route::domain('{slug}.domain.com')->group(function () {
    Route::get('/', 'CompanyController@company')->name('company2');
});
trifek's avatar

@tykus Yes, it's true. I have 2 routes to the same Controller. It's ok.

https://domain.com/firma/firma-2 and https: //firma-2.domain.com - this it the same page :)

firma-2 - it's slug (or subdomain). domain.com - this is my main domain :)

trifek's avatar

@tykus No. ;) Again. https://domain.com/firma/firma-2 and https: //firma-2.domain.com - this it the same page :) firma-2 - it's slug (or subdomain). domain.com - this is my main domain :)

my route:

Route::get('/firma/{slug}', 'CompanyController@company')->name('company');

Route::domain('{slug}.domain.com')->group(function () {
    Route::get('/', 'CompanyController@company')->name('company2');
});

Nów, when I open: https://domain.com/firma/firma-2 - I see company view. It's okey. When I open: https: //firma-2.domain.com - Iahve mainpage (main page = domain.com).

tykus's avatar

@trifek How are you actually serving this application?

Is your web server configured to handle subdomains?

trifek's avatar

Yes, I have application on hosting and it's configured to wildcard

trifek's avatar

Solution is:

Route::get('/firma/{slug}', 'CompanyController@company')->name('company');

Route::domain('{slug}.'. config("app.url"))->group(function () {
    Route::get('/', 'CompanyController@company')->name('company2');
});

tykus's avatar

@trifek why is this different to whatever I posted earlier? config('app.url') aside; it is the same thing...

Sinnbeck's avatar

@trifek doesn't config('app.url') have https:// in the url?

So you are saying this works?

Route::domain('{slug}.https://website.com') 
Sinnbeck's avatar

@trifek I honestly don't see how that would ever work.. Or work better than the correct way of doing it..

trifek's avatar

@Sinnbeck How should it be correct? How should it be correct? If this current solution is not correct then I would prefer to correct it and apply the correct solution .... :)

tykus's avatar
tykus
Best Answer
Level 104

@trifek this:

Route::get('/firma/{slug}', 'CompanyController@company')->name('company');

Route::domain('{slug}.domain.com')->group(function () {
    Route::get('/', 'CompanyController@company')->name('company2');
});
1 like

Please or to participate in this conversation.