diff --git a/app/Mail/Admin/EntityFailedSendObject.php b/app/Mail/Admin/EntityFailedSendObject.php index 124263f3ab..cc06af31cc 100644 --- a/app/Mail/Admin/EntityFailedSendObject.php +++ b/app/Mail/Admin/EntityFailedSendObject.php @@ -46,6 +46,31 @@ class EntityFailedSendObject { $this->invitation = $invitation; $this->entity_type = $entity_type; + + // Load relationships if they're not already loaded (e.g., when withoutRelations() was called) + if (!$invitation->relationLoaded('contact')) { + $invitation->load('contact'); + } + if (!$invitation->relationLoaded('company')) { + $invitation->load('company.account'); + } else { + // If company is loaded, ensure account is also loaded + if ($invitation->company && !$invitation->company->relationLoaded('account')) { + $invitation->company->load('account'); + } + } + if (!$invitation->relationLoaded($entity_type)) { + $invitation->load([$entity_type => function ($query) { + $query->with('client'); + }]); + } else { + // If entity is loaded, ensure client is also loaded + $entity = $invitation->{$entity_type}; + if ($entity && !$entity->relationLoaded('client')) { + $entity->load('client'); + } + } + $this->entity = $invitation->{$entity_type}; $this->contact = $invitation->contact; $this->company = $invitation->company;