60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\HasUniqueField;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property string $name Name of the archived site.
|
|
* @property string $site_id Id of the archived site.
|
|
* @property-read \Carbon\Carbon $created_at Created date.
|
|
* @property-read \Carbon\Carbon $updated_at Updated date.
|
|
*
|
|
* @property-read \App\Models\ArchiveCampaign $archiveCampaign ArchiveCampaign Has many relationship.
|
|
*/
|
|
class ArchiveSite extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUniqueField;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'site_id',
|
|
];
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $model) {
|
|
$model->assertFieldIsUnique('site_id', $model->site_id);
|
|
});
|
|
static::updating(function (self $model) {
|
|
throw new \RuntimeException('Updating an archived site is not authorized');
|
|
});
|
|
static::deleting(function () {
|
|
throw new \RuntimeException('Deleting an archived site is not authorized');
|
|
});
|
|
}
|
|
|
|
// * RELATIONS
|
|
|
|
/**
|
|
* ArchiveCampaign model relation
|
|
* @return Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function archiveCampaign()
|
|
{
|
|
return $this->hasMany(ArchiveCampaign::class);
|
|
}
|
|
}
|