I'm trying to make it so that I can have all routes inside of a group automatically use a domain parameter without having to specify it in views and whatnot. Here is an example of what I am looking for.
Route group code:
Route::group(['domain' => '{tenant_domain}.myapp.com', 'middleware' => 'tenant'], function () {
The tenant
middleware handle:
public function handle($request, $next)
{
session(['tenant_domain' => $request->route('tenant_domain')]);
return $next($request);
}
So instead of having to use this code in all my views:
{{ route('login', ['tenant_domain' => session('tenant_domain')]) }}
I'd like to only use:
{{ route('login') }}
And then in the boot()
method of RouteServiceProvider
, have something like:
public function boot()
{
if (isset(session('my_parameter'))) {
Route::addParameter(['tenant_domain' => session('tenant_domain')]);
}
parent::boot();
}
How can I do this properly so it works?