55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use App\Traits\HasTagsLight;
|
|
|
|
class MailingList extends Model
|
|
{
|
|
use HasTagsLight;
|
|
|
|
protected $table = 'mailing_lists';
|
|
protected $fillable = ['tenant_id', 'user_id', 'nome', 'descrizione', 'attiva', 'firma_id', 'sender_account_id'];
|
|
|
|
protected $casts = ['attiva' => 'boolean'];
|
|
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function contatti(): HasMany
|
|
{
|
|
return $this->hasMany(MailingContact::class);
|
|
}
|
|
|
|
public function messaggi(): HasMany
|
|
{
|
|
return $this->hasMany(MailingMessaggio::class);
|
|
}
|
|
|
|
public function firma(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Firma::class);
|
|
}
|
|
|
|
public function senderAccount(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SenderAccount::class);
|
|
}
|
|
|
|
public function getIndividui()
|
|
{
|
|
return Individuo::whereHas('mailingContacts', function ($q) {
|
|
$q->where('mailing_list_id', $this->id)->where('opt_in', true);
|
|
})->get();
|
|
}
|
|
} |