feat: Aggiungi funzionalità di eliminazione per clienti e preventivi con gestione delle dipendenze

This commit is contained in:
2026-10-19 15:48:15 +02:00
parent d6a9978167
commit 31d5152d8c
20 changed files with 673 additions and 17 deletions
+17
View File
@@ -31,6 +31,16 @@ class Cliente extends Model
return $this->hasMany(Preventivo::class);
}
protected static function booted(): void
{
static::deleting(function (Cliente $cliente): void {
// Elimina di conseguenza i preventivi del cliente (con i relativi file)
// e revoca i token API usati per l'accesso al configuratore.
$cliente->preventivi()->get()->each->delete();
$cliente->tokens()->delete();
});
}
public function getNominativoAttribute(): string
{
if ($this->ragione_sociale) {
@@ -41,4 +51,11 @@ class Cliente extends Model
return $nome !== '' ? $nome : $this->username;
}
public function getNomeCompletoAttribute(): string
{
$nome = trim("{$this->nome} {$this->cognome}");
return $nome !== '' ? $nome : $this->username;
}
}