slug)) { $category->slug = Str::slug($category->name); } }); } // ==================== Relationships ==================== /** * Get all documents in this category */ public function documents() { return $this->hasMany(Document::class); } /** * Get active (non-archived) documents in this category */ public function activeDocuments() { return $this->hasMany(Document::class)->where('status', 'active'); } // ==================== Accessors ==================== /** * Get the count of active documents in this category */ public function getDocumentCountAttribute(): int { return $this->activeDocuments()->count(); } // ==================== Helper Methods ==================== /** * Get the icon with fallback */ public function getIconDisplay(): string { return $this->icon ?? '📄'; } /** * Get the access level label */ public function getAccessLevelLabel(): string { return match($this->default_access_level) { 'public' => '公開', 'members' => '會員', 'admin' => '管理員', 'board' => '理事會', default => '未知', }; } }