ahmadmayahi
2 weeks ago
149
7
Laravel

Route::domain doesn't get URL::defaults values

Posted 2 weeks ago by ahmadmayahi

Hi everybody,

I'm trying to create sub-domain routes using Route::domain as follows:

Route::domain('sub.{domain}')->group(function() {
    Route::get('hello', function() {
        return "Hello World";
    });
});

The domain placeholder should be coming from SetDefaultDomain middleware but it doesn't:

URL::defaults([
    'domain' => 'laravel-exam.test',
    'test' => 'test',
]);
// Doesn't work

http://sub.laravel-exam.test/hello

The test placeholder works just fine:

Route::get('myroute/{test}', function() {
    return 'Test';
});
// Works fine

http://laravel-exam.test/myroute/test

I also tried to add the URL::defaults in the RouteServiceProvider but it didn't work.

Any idea?

Please sign in or create an account to participate in this conversation.