reaction = $reaction; // Get the reacter (person making the reservation) $reacter = $reaction->getReacter()->getReacterable(); \Log::info('ReservationCreatedMail: Reacter loaded', ['name' => $reacter->name]); // Get the post (event being reserved) using the reactant's getReactable method $reactant = $reaction->getReactant(); $this->post = $reactant->getReactable(); // Eager load the relationships we need if ($this->post) { $this->post->load(['translations', 'meeting']); } \Log::info('ReservationCreatedMail: Post loaded', [ 'post_id' => $this->post ? $this->post->id : null, 'post_title' => $this->post && $this->post->translations->first() ? $this->post->translations->first()->title : null, 'has_meeting' => $this->post && $this->post->meeting ? 'yes' : 'no' ]); // 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('ReservationCreatedMail: 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('ReservationCreatedMail: Button URL created', ['url' => $this->buttonUrl, 'slug' => $translation->slug]); } } } /** * Build the message. * * @return $this */ public function build() { // Set application locale for this email app()->setLocale($this->locale); \Log::info('ReservationCreatedMail: Building email', [ 'locale' => $this->locale, 'template' => 'emails.reactions.reservation-confirmation', 'subject' => trans('messages.Reservation_confirmation', [], $this->locale), ]); return $this ->from(timebank_config('mail.support.email'), timebank_config('mail.support.name')) ->subject(trans('messages.Reservation_confirmation', [], $this->locale)) ->view('emails.reactions.reservation-confirmation') ->with([ 'reacter' => $this->reaction->getReacter()->getReacterable(), 'post' => $this->post, 'buttonUrl' => $this->buttonUrl, ]); } }