This commit is contained in:
Simon Pocrnjič 2024-11-19 20:29:04 +01:00
parent e804d6f4d5
commit 1620136d7d
3 changed files with 12 additions and 10 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,