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

lightstyle's avatar

Use "route()" in blade from route group domain? ()

This is my routes, a example is also here: https://laracasts.com/discuss/channels/laravel/how-to-set-correct-route-for-subdomain-homepage

Route::group(['domain' => 'maindomain.dev'], function () {
    Route::get('/', function () {
        return view('welcome');
    })->name('websitehome');
});

Route::group(['domain' => '{account}.maindomain.dev'], function () {
    Route::get('/', function () {
        return view('accountindex');
    })->name('accountindex');
});

if I use in blade route('websitehome') it works, it's from route domain, but if I want to get route from subdomain like route('accountindex') then I get this error msg.

ErrorException in UrlGenerationException.php line 17: Missing required parameters for [Route: accountindex] [URI: account].

What is here to add to route()?

0 likes
6 replies
Reached's avatar

route('accountindex', $account) <-- Could you try to add the $account variable there (or whatever you call it in your view)

So a link would be:

<a href="{{ route('accountindex', $account) }}">Link to account</a>
lightstyle's avatar

@Reached Where I have to define this variable? I get now following error: Undefined variable: account path_to_blade

Reached's avatar

Okay my bad, I thought that you had an account variable available in your view. So you have to use the account in your view,

E.g. in your method that loads the view:

public function show($account) {
        $account = Account::findOrFail($account)->first();

        return view('account.show', compact('account'));
    }
            

I have no idea how that part of your code looks, but maybe the above will give you an idea, otherwise you have to show me your method that loads the view :)

lightstyle's avatar

Maybe it works, but I have to implement it into master.blade.php, so it is global, I found following {{ route('accountindex', ['account']) }}, but the subdomain name is now static, can I get it dynamically? Something like to set name on route group.

Reached's avatar

Can't you just send it to your master blade file through a controller method? Or even just use a view composer to make it available globally.

lightstyle's avatar

Don't have idea how to do this because I have routes and want to have their link on a specific place in my master file.

Please or to participate in this conversation.