$reacter->id, 'post_id' => $post->id ]); $this->reacter = $reacter; $this->post = $post; $this->message = $message; $this->organizer = $organizer; // Eager load the relationships we need if ($this->post) { $this->post->load(['translations', 'meeting']); } // Support lang_preference for User, Organization, Bank, and Admin models $this->locale = $reacter->lang_preference ?? config('app.fallback_locale'); // Ensure locale is not empty if (empty($this->locale)) { $this->locale = config('app.fallback_locale'); } Log::info('ReservationUpdateMail: Locale set', ['locale' => $this->locale]); // Button should link to the event/post using the slug if ($this->post && isset($this->post->id)) { // Get the translation for the user's locale $translation = $this->post->translations->where('locale', $this->locale)->first(); // Fall back to first translation if locale not found if (!$translation) { $translation = $this->post->translations->first(); } if ($translation && $translation->slug) { $this->buttonUrl = LaravelLocalization::localizeURL(route('post.show_by_slug', ['slug' => $translation->slug]), $this->locale); Log::info('ReservationUpdateMail: Button URL created', ['url' => $this->buttonUrl]); } } } /** * Build the message. * * @return $this */ public function build() { // Set application locale for this email app()->setLocale($this->locale); Log::info('ReservationUpdateMail: Building email', [ 'locale' => $this->locale, 'template' => 'emails.reactions.reservation-update', 'subject' => trans('messages.Reservation_update', [], $this->locale), ]); return $this ->from(timebank_config('mail.support.email'), timebank_config('mail.support.name')) ->subject(trans('messages.Reservation_update', [], $this->locale)) ->view('emails.reactions.reservation-update') ->with([ 'reacter' => $this->reacter, 'post' => $this->post, 'customMessage' => $this->message, 'organizer' => $this->organizer, 'buttonUrl' => $this->buttonUrl, ]); } }