'boolean', 'ultimo_accesso_at' => 'datetime', ]; public function fornitore() { return $this->belongsTo(Fornitore::class, 'fornitore_id'); } public function user() { return $this->belongsTo(User::class, 'user_id'); } public function fornitoreEsterno() { return $this->belongsTo(Fornitore::class, 'fornitore_esterno_id'); } public function rubrica() { return $this->belongsTo(RubricaUniversale::class, 'rubrica_id'); } public function creatoDaUser() { return $this->belongsTo(User::class, 'created_by_user_id'); } public function aggiornatoDaUser() { return $this->belongsTo(User::class, 'updated_by_user_id'); } public function getNomeCompletoAttribute(): string { $label = trim((string) ($this->nome . ' ' . ($this->cognome ?? ''))); if ($label !== '') { return $label; } $supplierLabel = trim((string) ($this->fornitoreEsterno?->ragione_sociale ?: trim((string) (($this->fornitoreEsterno?->nome ?? '') . ' ' . ($this->fornitoreEsterno?->cognome ?? ''))))); return $supplierLabel !== '' ? $supplierLabel : 'Collaboratore fornitore'; } public function getTipoLabelAttribute(): string { return match ((string) $this->tipo_collaboratore) { self::TIPO_FORNITORE_ESTERNO => 'Altro fornitore', default => 'Collaboratore interno', }; } public function getRuoloOperativoLabelAttribute(): string { if ((string) $this->tipo_collaboratore === self::TIPO_FORNITORE_ESTERNO) { $supplierLabel = trim((string) ($this->fornitoreEsterno?->ragione_sociale ?: trim((string) (($this->fornitoreEsterno?->nome ?? '') . ' ' . ($this->fornitoreEsterno?->cognome ?? ''))))); return $supplierLabel !== '' ? 'Subfornitore: ' . $supplierLabel : 'Subfornitore esterno'; } return $this->nome_completo !== '' ? $this->nome_completo : 'Collaboratore interno'; } }