Initial commit

This commit is contained in:
2025-11-20 23:21:05 +08:00
commit 13bc6db529
378 changed files with 54527 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class DocumentCategory extends Model
{
use HasFactory;
protected $fillable = [
'name',
'slug',
'description',
'icon',
'sort_order',
'default_access_level',
];
protected static function boot()
{
parent::boot();
// Auto-generate slug from name if not provided
static::creating(function ($category) {
if (empty($category->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 => '未知',
};
}
}