netgescon-day0/app/Models/Condomino.php

32 lines
961 B
PHP
Executable File

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Condomino extends Model
{
protected $table = 'condomini';
protected $guarded = [];
public function getDisplayNameAttribute(): string
{
$cognome = is_string($this->cognome ?? null) ? trim((string) $this->cognome) : '';
$nome = is_string($this->nome ?? null) ? trim((string) $this->nome) : '';
$ragione = is_string($this->ragione_sociale ?? null) ? trim((string) $this->ragione_sociale) : '';
$cod = is_string($this->cod_cond ?? null) ? trim((string) $this->cod_cond) : '';
$full = trim($cognome . ' ' . $nome);
if ($full !== '') {
return $cod !== '' ? ($full . ' (' . $cod . ')') : $full;
}
if ($ragione !== '') {
return $cod !== '' ? ($ragione . ' (' . $cod . ')') : $ragione;
}
return $cod !== '' ? $cod : ('Condomino #' . (string) $this->getKey());
}
}