ldc-mesbr-app/app/Models/ArchiveCoupon.php
2026-10-28 13:23:49 +01:00

61 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 coupon.
* @property string $coupon_code Treatment code of the archived coupon.
* @property-read \Carbon\Carbon $created_at Created date.
* @property-read \Carbon\Carbon $updated_at Updated date.
*
* @property-read \App\Models\ArchiveStat $archiveStat ArchiveStat Has many relationship.
*/
class ArchiveCoupon extends Model
{
use HasFactory;
use HasUniqueField;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'coupon_code',
];
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted(): void
{
static::creating(function (self $model): void {
$model->assertFieldIsUnique('coupon_code', $model->coupon_code);
});
static::updating(function (): void {
throw new \RuntimeException('Updating an archived coupon is not authorized');
});
static::deleting(function (): void {
throw new \RuntimeException('Deleting an archived coupon is not authorized');
});
}
// * RELATIONS
/**
* ArchiveStat model relation
* @return Illuminate\Database\Eloquent\Relations\HasMany
*/
public function archiveStat()
{
return $this->hasMany(ArchiveStat::class);
}
}