This commit is contained in:
Simon Pocrnjič 2024-11-19 21:29:53 +01:00
parent e66eb6436c
commit 713bd9ffe3
4 changed files with 18 additions and 18 deletions

View File

@ -35,16 +35,12 @@ protected function makeAllSearchableUsing(Builder $query): Builder
public function toSearchableArray(): array
{
/*$person = [
'full_name' => $this->person->full_name,
'addresses' => $this->person->addresses,
'phones' => $this->person->phones
];*/
$this->loadMissing('person');
$array = $this->toArray();
$array['person_full_name'] = $this->person ? $this->person->full_name: null;
$array['person'] = $this->person ? $this->person->only(['full_name', 'tax_number', 'social_security_number']): null;
$array['person_addresses'] = $this->person->addresses ? $this->person->addresses->only(['adddress'])->toArray() : [];
$array['person_phones'] = $this->person->phones ? $this->person->phones->only(['nu'])->toArray() : [];
return $array;
}

View File

@ -34,11 +34,11 @@ protected function makeAllSearchableUsing(Builder $query): Builder
public function toSearchableArray(): array
{
$this->loadMissing('person');
$array = $this->toArray();
$array['person_full_name'] = $this->person ? $this->person->full_name: null;
$array['person'] = $this->person ? $this->person->only(['full_name', 'tax_number', 'social_security_number']): null;
$array['person_addresses'] = $this->person->addresses ? $this->person->addresses->only(['adddress'])->toArray() : [];
$array['person_phones'] = $this->person->phones ? $this->person->phones->only(['nu'])->toArray() : [];
return $array;
}

View File

@ -42,6 +42,7 @@ class Person extends Model
];
protected $hidden = [
'id',
'deleted',
'user_id'
];

View File

@ -6,6 +6,7 @@
use App\Http\Controllers\ContractController;
use App\Http\Controllers\SettingController;
use App\Models\Person\Person;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use ArielMejiaDev\LarapexCharts\LarapexChart;
use Illuminate\Support\Facades\Route;
@ -50,14 +51,16 @@
})
->get();*/
$clients = App\Models\Client::search($request->input('query'))
->get()
->load('person:id,full_name')
->take(5);
->query( fn(Builder $builder) =>
$builder->with('person:id,full_name')->limit($request->input('limit'))
)
->get();
$clientCases = App\Models\ClientCase::search($request->input('query'))
->get()
->load('person:id,full_name')
->take(5);
->query( fn(Builder $builder) =>
$builder->with('person:id,full_name')->limit($request->input('limit'))
)
->get();
return [