*/ use HasFactory, LogsActivity, SoftDeletes; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'workspace_id', 'company_name', 'legal_form', 'ice', 'fiscal_id', 'rc', 'cnss', 'patente', 'contact_last_name', 'contact_first_name', 'contact_job_title', 'contact_email', 'contact_phone', 'internal_responsible_id', 'status', 'internal_notes', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'legal_form' => LegalForm::class, 'status' => ClientStatus::class, ]; } /** * Get the workspace that owns the client. * * @return BelongsTo */ public function workspace(): BelongsTo { return $this->belongsTo(Workspace::class); } /** * Get the internal responsible user. * * @return BelongsTo */ public function internalResponsible(): BelongsTo { return $this->belongsTo(User::class, 'internal_responsible_id'); } /** * Get the contacts for the client. * * @return HasMany */ public function contacts(): HasMany { return $this->hasMany(ClientContact::class); } /** * Get the primary contact for the client. * * @return HasOne */ public function primaryContact(): HasOne { return $this->hasOne(ClientContact::class)->where('is_principal', true)->latest(); } public function getPrimaryContactEmailAttribute(): ?string { return $this->primaryContact?->email ?? $this->contact_email; } /** * Get the declarations for the client. * * @return HasMany */ public function declarations(): HasMany { return $this->hasMany(Declaration::class); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logFillable() ->logOnlyDirty() ->dontSubmitEmptyLogs(); } }