I have a problem capturing the domain in the routes file.
When a route is written like this:
Route::domain('mydomain.com')
->get('/', function () {
return "It works";
});
And I access mydomain.com, I correctly get status 200 and a string It works.
But when the routes are changed to this:
Route::domain('{domain}')
->get('/', function () {
return "It works";
});
It is not getting picked up and I get 404.
I was also trying:
Route::bind('domain', function () {
return 'mydomain.com';
});
Route::domain('{domain}')
->get('/', function () {
return "It works";
});
But it is not working either.
Any idea what am I doing wrong?
>Solution :
Define a custom pattern for the {domain} parameter using regular expressions.
Route::pattern('domain', '[a-z0-9.-]+'); // Define pattern for the domain parameter
Route::domain('{domain}')
->get('/', function ($domain) {
return "It works for {$domain}";
});