Contact show page layz load issue fixed..

This commit is contained in:
Cüneyt Şentürk 2026-01-18 01:04:46 +00:00
parent fb9f7eaaa3
commit 4829c7728d
2 changed files with 18 additions and 4 deletions

View File

@ -36,8 +36,10 @@ class Content extends Component
// Handle documents // Handle documents
$docs = $this->contact->isCustomer() ? 'invoices' : 'bills'; $docs = $this->contact->isCustomer() ? 'invoices' : 'bills';
// Eager load transactions with currency to prevent N+1 queries when calling getAmountConvertedToDefault() // Eager load documents with necessary relations to prevent lazy loading
$this->documents = $this->contact->$docs()->with(['transactions', 'transactions.currency'])->get(); $this->documents = $this->contact->$docs()
->with(['transactions', 'transactions.currency', 'contact', 'last_history', 'items', 'totals'])
->get();
$this->counts['documents'] = $this->documents->count(); $this->counts['documents'] = $this->documents->count();
@ -63,8 +65,10 @@ class Content extends Component
} }
} }
// Handle payments - eager load currency to prevent N+1 queries // Handle payments - eager load necessary relations to prevent lazy loading
$this->transactions = $this->contact->transactions()->with(['account', 'category', 'currency'])->get(); $this->transactions = $this->contact->transactions()
->with(['account', 'category', 'currency', 'contact', 'document', 'recurring'])
->get();
$this->counts['transactions'] = $this->transactions->count(); $this->counts['transactions'] = $this->transactions->count();

View File

@ -35,6 +35,16 @@ class Information extends Component
) { ) {
$this->document = $document; $this->document = $document;
$this->hideShow = $hideShow; $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->showRoute = $this->getShowRoute($document->contact->type, $showRoute);
$this->showDocumentRoute = $this->getShowRoute($document->type, $showDocumentRoute); $this->showDocumentRoute = $this->getShowRoute($document->type, $showDocumentRoute);
$this->placement = (! empty($placement)) ? $placement : 'left'; $this->placement = (! empty($placement)) ? $placement : 'left';