From 1620136d7d099b59e8a1d00f4aab312d311b10ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Pocrnji=C4=8D?= Date: Tue, 19 Nov 2024 20:29:04 +0100 Subject: [PATCH] fix 4 --- app/Models/Client.php | 3 +-- app/Models/ClientCase.php | 3 +-- routes/web.php | 16 ++++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/Models/Client.php b/app/Models/Client.php index dea767a..c42f570 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -41,10 +41,9 @@ public function toSearchableArray(): array 'phones' => $this->person->phones ];*/ - $this->loadMissing('person'); $array = $this->toArray(); - $array['person'] = $this->person ? $this->person->toArray() : []; + $array['person'] = $this->person ? $this->person->only('full_name') : null; return $array; } diff --git a/app/Models/ClientCase.php b/app/Models/ClientCase.php index 58cbb7b..f7507da 100644 --- a/app/Models/ClientCase.php +++ b/app/Models/ClientCase.php @@ -34,10 +34,9 @@ protected function makeAllSearchableUsing(Builder $query): Builder public function toSearchableArray(): array { - $this->loadMissing('person'); $array = $this->toArray(); - $array['person'] = $this->person ? $this->person->toArray() : []; + $array['person'] = $this->person ? $this->person->only('full_name') : null; return $array; } diff --git a/routes/web.php b/routes/web.php index e993a90..e772551 100644 --- a/routes/web.php +++ b/routes/web.php @@ -44,17 +44,21 @@ Route::get('search', function(Request $request) { if( !empty($request->input('query')) ) { - $clients = App\Models\Client::search($request->input('query')) + /*$clients = App\Models\Client::search($request->input('query')) ->query(function($q) use($request) { $q->with('person')->limit($request->input('limit')); }) - ->get(); + ->get();*/ + $clients = App\Models\Client::search($request->input('query')) + ->get() + ->load('person:id,full_name') + ->take(5); $clientCases = App\Models\ClientCase::search($request->input('query')) - ->query(function($q) use($request) { - $q->with('person')->limit($request->input('limit')); - }) - ->get(); + ->get() + ->load('person:id,full_name') + ->take(5); + return [ 'clients' => $clients,