66 lines
1.4 KiB
PHP
66 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\Uuid;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Laravel\Scout\Searchable;
|
|
|
|
class ClientCase extends Model
|
|
{
|
|
/** @use HasFactory<\Database\Factories\ClientCaseFactory> */
|
|
use HasFactory;
|
|
use Uuid;
|
|
use Searchable;
|
|
|
|
protected $fillable = [
|
|
'client_id'
|
|
];
|
|
|
|
protected $hidden = [
|
|
'id',
|
|
'client_id',
|
|
'person_id'
|
|
];
|
|
|
|
protected function makeAllSearchableUsing(Builder $query): Builder
|
|
{
|
|
return $query->with('person');
|
|
}
|
|
|
|
public function toSearchableArray(): array
|
|
{
|
|
$this->loadMissing('person');
|
|
|
|
$array = $this->toArray();
|
|
|
|
$array['person_full_name'] = $this->person ? $this->person->full_name: null;
|
|
|
|
return $array;
|
|
}
|
|
|
|
public function client(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Client::class);
|
|
}
|
|
|
|
public function person(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Person\Person::class);
|
|
}
|
|
|
|
public function contracts(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Models\Contract::class);
|
|
}
|
|
|
|
public function activities(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Models\Activity::class);
|
|
}
|
|
}
|