1

I registered following routes on my web.php file

Route::domain('{domain}.project.test')->group(function () {
    Route::get('/', function ($domain) {
        return view('welcome',compact('domain'));
    });

    Auth::routes(['verify' => true]);

    Route::get('/home', 'HomeController@index')->name('home')->middleware('verified');

});

I had to pass the domain variable into welcome.blade.php in order to pass it into route() method

<div class="top-right links">
        @auth
            <a href="{{ url('/home') }}">Home</a>
        @else
            <a href="{{ route('login',$domain) }}">Login</a>
            <a href="{{ route('register',$domain) }}">Register</a>
        @endauth
    </div>

is there any way to pass$domain variable on to the route() method by default

1 Answers1

0

You can write a custom helper function, something like droute() below:

if (! function_exists('droute')) {
    function droute($name, $parameters = [], $absolute = true)
    {
        $parameters['domain'] = app('request')->route('domain');
        return app('url')->route($name, $parameters, $absolute);
    }
}

Here is a link on how to create custom helpers.

dparoli
  • 8,891
  • 1
  • 30
  • 38
  • Anyway, thank you for the helper method it works. But I am still facing some other issue relating default *laravel email verification* . – Navaneeth Raman Bhaskar Aug 17 '19 at 09:53
  • You're welcome, for the email verification problem it's better to open another question to leave this one clean.. – dparoli Aug 17 '19 at 10:47
  • It is related to the same problem. I have got the following error because of Laravel `route()` method. need `$domain` parameter `Illuminate \ Routing \ Exceptions \ UrlGenerationException Missing required parameters for [Route: verification.notice] [URI: email/verify].` – Navaneeth Raman Bhaskar Aug 17 '19 at 17:33
  • Yes but it's better to open another question, this is the way SO works. – dparoli Aug 17 '19 at 17:39