2026-05-26 08:14:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
|
|
|
|
class MailingMessaggio extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $table = 'mailing_messaggi';
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'tenant_id', 'mailing_list_id', 'user_id', 'oggetto', 'corpo',
|
2026-05-27 07:29:29 +02:00
|
|
|
'canale', 'stato', 'inviato_al', 'totale_destinatari', 'invii_ok', 'invii_falliti',
|
2026-06-23 08:05:51 +02:00
|
|
|
'log_falliti', 'mittente_nome', 'mittente_email', 'firma_id',
|
2026-05-26 08:14:29 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'inviato_al' => 'datetime',
|
2026-05-27 07:29:29 +02:00
|
|
|
'log_falliti' => 'array',
|
2026-05-26 08:14:29 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function tenant(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Tenant::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function mailingList(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(MailingList::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function user(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isInviato(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->stato === 'inviato';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function canBeSent(): bool
|
|
|
|
|
{
|
|
|
|
|
return in_array($this->stato, ['bozza', 'fallito']);
|
|
|
|
|
}
|
|
|
|
|
}
|