84 lines
2.1 KiB
PHP
84 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Person;
|
|
|
|
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 Laravel\Sanctum\HasApiTokens;
|
|
|
|
class Person extends Model
|
|
{
|
|
use HasApiTokens;
|
|
/** @use HasFactory<\Database\Factories\Person/PersonFactory> */
|
|
use HasFactory;
|
|
use Uuid;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $table = 'person';
|
|
protected $fillable = [
|
|
'nu',
|
|
'first_name',
|
|
'last_name',
|
|
'full_name',
|
|
'gender',
|
|
'birthday',
|
|
'tax_number',
|
|
'social_security_number',
|
|
'description',
|
|
'group_id',
|
|
'type_id',
|
|
'user_id'
|
|
];
|
|
|
|
protected $hidden = [
|
|
'id',
|
|
'deleted',
|
|
'user_id'
|
|
];
|
|
|
|
|
|
public function phones(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Models\Person\PersonPhone::class)
|
|
->with(['type'])
|
|
->where('active','=',1);
|
|
}
|
|
|
|
public function addresses(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Models\Person\PersonAddress::class)
|
|
->with(['type'])
|
|
->where('active','=',1);
|
|
}
|
|
|
|
public function group(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Person\PersonGroup::class, 'group_id');
|
|
}
|
|
|
|
public function type(): BelongsTo
|
|
{
|
|
return $this->belongsTo(\App\Models\Person\PersonType::class, 'type_id');
|
|
}
|
|
|
|
public function contracts(): HasMany
|
|
{
|
|
return $this->hasMany(\App\Models\Contract::class, 'client_id')
|
|
->with('debtor', fn($que) =>
|
|
$que->with(['type', 'group'])
|
|
->whereHas('type', fn($tque) => $tque->where('deleted','=',0))
|
|
->whereHas('group', fn($tque) => $tque->where('deleted','=',0))
|
|
->where('active','=',1))
|
|
->with('type', fn($que) => $que->where('deleted','=',0))
|
|
->where('active', '=', 1);
|
|
}
|
|
|
|
}
|