profile = $profile; $this->convertedTo = $convertedTo; $this->manager = $manager; $this->locale = $profile->lang_preference ?? config('app.fallback_locale'); if (empty($this->locale)) { $this->locale = config('app.fallback_locale'); } $profileClass = get_class($profile); $mainPath = LaravelLocalization::getURLFromRouteNameTranslated($this->locale, 'routes.main'); $mainUrl = url($mainPath); if ($profileClass === 'App\\Models\\User') { $this->buttonUrl = LaravelLocalization::localizeURL( route('user.direct-login', ['userId' => $profile->id, 'intended' => $mainUrl, 'name' => $profile->name]), $this->locale ); } elseif ($profileClass === 'App\\Models\\Organization') { // Button goes to the organization via the manager's direct-login, // pre-filling the manager's username at the login page if ($manager) { $orgUrl = LaravelLocalization::localizeURL( route('organization.direct-login', ['organizationId' => $profile->id]), $this->locale ); $this->buttonUrl = LaravelLocalization::localizeURL( route('user.direct-login', ['userId' => $manager->id, 'intended' => $orgUrl, 'name' => $manager->name]), $this->locale ); } else { $this->buttonUrl = LaravelLocalization::localizeURL( route('organization.direct-login', ['organizationId' => $profile->id, 'intended' => $mainUrl]), $this->locale ); } } else { $this->buttonUrl = LaravelLocalization::localizeURL(route('login'), $this->locale); } Log::info('ProfileConvertedByAdminMail: Constructor called', [ 'profile_id' => $profile->id, 'profile_type' => $profileClass, 'converted_to' => $convertedTo, 'manager_id' => $manager?->id, 'button_url' => $this->buttonUrl, ]); } public function build() { app()->setLocale($this->locale); $subject = trans('messages.profile_converted_by_admin_subject', [], $this->locale); return $this ->from(timebank_config('mail.support.email'), timebank_config('mail.support.name')) ->subject($subject) ->view('emails.profile-converted.profile-converted') ->with([ 'profile' => $this->profile, 'convertedTo' => $this->convertedTo, 'manager' => $this->manager, 'buttonUrl' => $this->buttonUrl, ]); } }