belongsTo(Registry::class); } public function category(): BelongsTo { return $this->belongsTo(Category::class); } public function asset(): BelongsTo { return $this->belongsTo(Asset::class); } public function operations(): MorphToMany { return $this->objectsByGroup('operations')->reorder()->applyOrders(['order-date' => 'desc']); } public function getPropertiesAttribute(): ?Model { return ($type = $this->registry->parsedType['options']['properties'] ?? null) ? $this->getObject($type, 'properties') : null; } public function getStateAttribute(): ?array { $state = null; if ($this->active_since) { $state = ($this->active_since <= now()) ? EntryState::ACTIVE : EntryState::AWAITING; if ($this->active_till && ($this->active_till <= now())) $state = EntryState::EXPIRED; elseif ($this->cancelled_at && ($this->cancelled_at <= now())) $state = EntryState::CANCELLED; elseif ($this->suspended_since && ($this->suspended_since <= now()) && (!$this->suspended_till || ($this->suspended_till > now()))) $state = EntryState::SUSPENDED; } return $state ? ['name' => $state, 'title' => EntryState::TITLES[$state] ?? null] : null; } }