diff --git a/app/View/Components/Contacts/Show/Content.php b/app/View/Components/Contacts/Show/Content.php index c365f28d8..92049f753 100644 --- a/app/View/Components/Contacts/Show/Content.php +++ b/app/View/Components/Contacts/Show/Content.php @@ -36,8 +36,10 @@ class Content extends Component // Handle documents $docs = $this->contact->isCustomer() ? 'invoices' : 'bills'; - // Eager load transactions with currency to prevent N+1 queries when calling getAmountConvertedToDefault() - $this->documents = $this->contact->$docs()->with(['transactions', 'transactions.currency'])->get(); + // Eager load documents with necessary relations to prevent lazy loading + $this->documents = $this->contact->$docs() + ->with(['transactions', 'transactions.currency', 'contact', 'last_history', 'items', 'totals']) + ->get(); $this->counts['documents'] = $this->documents->count(); @@ -63,8 +65,10 @@ class Content extends Component } } - // Handle payments - eager load currency to prevent N+1 queries - $this->transactions = $this->contact->transactions()->with(['account', 'category', 'currency'])->get(); + // Handle payments - eager load necessary relations to prevent lazy loading + $this->transactions = $this->contact->transactions() + ->with(['account', 'category', 'currency', 'contact', 'document', 'recurring']) + ->get(); $this->counts['transactions'] = $this->transactions->count(); diff --git a/app/View/Components/Documents/Index/Information.php b/app/View/Components/Documents/Index/Information.php index b270c6a45..6bfb21ab1 100644 --- a/app/View/Components/Documents/Index/Information.php +++ b/app/View/Components/Documents/Index/Information.php @@ -35,6 +35,16 @@ class Information extends Component ) { $this->document = $document; $this->hideShow = $hideShow; + + // Load relations if not loaded to prevent lazy loading + $relations = ['contact', 'last_history', 'items', 'totals']; + + foreach ($relations as $relation) { + if (! $document->relationLoaded($relation)) { + $document->load($relation); + } + } + $this->showRoute = $this->getShowRoute($document->contact->type, $showRoute); $this->showDocumentRoute = $this->getShowRoute($document->type, $showDocumentRoute); $this->placement = (! empty($placement)) ? $placement : 'left';