43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Catalog;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class BundleVersion extends Model
|
|
{
|
|
protected $fillable = [
|
|
'bundle_id',
|
|
'number',
|
|
'status',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'status' => BundleStatus::class,
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::updating(function (BundleVersion $version): void {
|
|
if (StatusValue::of($version->getOriginal('status')) === BundleStatus::Veroeffentlicht->value) {
|
|
throw new DomainRuleException('Eine veröffentlichte Paketfassung ist unveränderlich.');
|
|
}
|
|
});
|
|
}
|
|
|
|
public function bundle(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Bundle::class);
|
|
}
|
|
|
|
public function items(): HasMany
|
|
{
|
|
return $this->hasMany(BundleItem::class)->orderBy('position');
|
|
}
|
|
}
|