From e804d6f4d55870924baa57a504c6b67ed6c948bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Pocrnji=C4=8D?= Date: Tue, 19 Nov 2024 19:50:47 +0100 Subject: [PATCH] fix 3 --- app/Models/Client.php | 9 ++++++--- app/Models/ClientCase.php | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index c4e7ce6..dea767a 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -41,9 +41,12 @@ public function toSearchableArray(): array 'phones' => $this->person->phones ];*/ - return [ - 'person' => $this->person->toArray() - ]; + $this->loadMissing('person'); + $array = $this->toArray(); + + $array['person'] = $this->person ? $this->person->toArray() : []; + + return $array; } diff --git a/app/Models/ClientCase.php b/app/Models/ClientCase.php index adc9aae..58cbb7b 100644 --- a/app/Models/ClientCase.php +++ b/app/Models/ClientCase.php @@ -34,11 +34,12 @@ protected function makeAllSearchableUsing(Builder $query): Builder public function toSearchableArray(): array { - return [ - 'person' => $this->person, - 'addresses' => $this->person->addresses, - 'phones' => $this->person->phones - ]; + $this->loadMissing('person'); + $array = $this->toArray(); + + $array['person'] = $this->person ? $this->person->toArray() : []; + + return $array; } public function client(): BelongsTo