44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class MailAlias extends Model
|
|
{
|
|
protected $fillable = ['domain_id','local','type','group_name','is_active','notes'];
|
|
protected $casts = ['is_active' => 'bool'];
|
|
|
|
public function domain(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Domain::class);
|
|
}
|
|
|
|
public function recipients(): HasMany
|
|
{
|
|
return $this->hasMany(MailAliasRecipient::class, 'alias_id');
|
|
}
|
|
|
|
public function getAddressAttribute(): string
|
|
{
|
|
$domain = $this->relationLoaded('domain') ? $this->domain : $this->domain()->first();
|
|
return "{$this->local}@{$domain->name}";
|
|
}
|
|
|
|
// protected $table = 'mail_aliases';
|
|
//
|
|
// protected $fillable = ['domain_id','source','destination','is_active'];
|
|
// protected $casts = ['is_active'=>'bool'];
|
|
//
|
|
// public function domain(): BelongsTo {
|
|
// return $this->belongsTo(Domain::class);
|
|
// }
|
|
//
|
|
public function getSourceAttribute(): string {
|
|
return "{$this->source_local}@{$this->domain->name}";
|
|
}
|
|
|
|
}
|