belongsTo(Page::class); } public function categories(): HasMany { return $this->hasMany(Category::class); } public function rootCategories(): HasMany { return $this->categories()->where(['parent_id' => 0]); } public function entries(): HasMany { return $this->hasMany(Entry::class); } public function getParsedTypeAttribute(): array { return ['name' => $this->type, 'title' => RegistryType::TITLES[$this->type] ?? null, 'options' => $this->options]; } public function getOptionsAttribute(): array { return RegistryType::OPTIONS[$this->type] ?? []; } public function addCategory(string $name): ?Model { $res = $this->categories()->where(['name' => $name])->first(); if (!$res) { $res = $this->categories()->create(['name' => $name]); $res->update(['ord' => $res->getMaxOrd()]); } return $res; } }