fix mailing an email

This commit is contained in:
2026-06-23 08:05:51 +02:00
parent c5127da750
commit def8d22544
2479 changed files with 325393 additions and 781 deletions
+21 -2
View File
@@ -24,6 +24,8 @@ class Gruppo extends Model
'responsabile_ids' => 'array',
];
protected $appends = ['email_primaria', 'telefono_primario'];
public function tenant(): BelongsTo
{
return $this->belongsTo(Tenant::class);
@@ -39,9 +41,14 @@ class Gruppo extends Model
return $this->hasMany(Gruppo::class, 'parent_id');
}
public function diocesi(): BelongsTo
public function diocesi(): BelongsToMany
{
return $this->belongsTo(Diocesi::class);
return $this->belongsToMany(Diocesi::class, 'diocesi_gruppo');
}
public function gruppoContatti(): HasMany
{
return $this->hasMany(GruppoContatto::class, 'gruppo_id');
}
public function individui(): BelongsToMany
@@ -66,6 +73,18 @@ class Gruppo extends Model
return null;
}
public function getEmailPrimariaAttribute(): ?string
{
return $this->gruppoContatti()->where('tipo', 'email')->where('is_primary', true)->first()?->valore
?? $this->gruppoContatti()->where('tipo', 'email')->first()?->valore;
}
public function getTelefonoPrimarioAttribute(): ?string
{
return $this->gruppoContatti()->whereIn('tipo', ['telefono', 'cellulare'])->where('is_primary', true)->first()?->valore
?? $this->gruppoContatti()->whereIn('tipo', ['telefono', 'cellulare'])->first()?->valore;
}
public function getResponsabili()
{
if (empty($this->responsabile_ids)) {