host())->first(); if ($space != null) { if (!str_ends_with($space->host, config('app.root_host'))) { abort(503, 'The APP_ROOT_HOST configured does not match with the current root domain'); } $request->merge(['space' => $space]); Config::set('app.url', '://' . $space->host); if ($space->isExpired()) { abort($request->expectsJson() ? 403 : 490, 'The related Space has expired'); } // Custom email integration if ($space->emailServer) { $config = [ 'driver' => config('mail.driver'), 'encryption' => config('mail.encryption'), 'host' => $space->emailServer->host, 'port' => $space->emailServer->port, 'from' => [ 'address' => $space->emailServer->from_address, 'name' => $space->emailServer->from_name ], 'username' => $space->emailServer->username, 'password' => $space->emailServer->password, 'signature' => $space->emailServer->signature ?? config('mail.signature') ] + Config::get('mail'); Config::set('mail', $config); } return $next($request); } abort(404, 'Host not configured'); } }