Files
sam-manage/app/Models/Boards/Board.php
kent cd6cf9746a feat(mng): 게시판-메뉴 자동 연동 및 URL 패턴 변경
## 주요 변경사항

### 게시판-메뉴 자동 연동
- 게시판 생성 시 메뉴 자동 생성 (BoardService.createBoardFromTemplate)
- 게시판 삭제 시 연결 메뉴 함께 삭제 (Soft Delete 연동)
- 게시판 복원 시 메뉴 재생성
- 게시판 영구삭제 시 메뉴 영구삭제

### 게시판 메뉴 보호
- MenuService: 게시판 연동 메뉴 수동 수정/삭제 방지
- isBoardMenuUrl(), isBoardMenu(), validateNotBoardUrl() 헬퍼 추가
- 8개 CRUD 메서드에 검증 로직 적용

### URL 패턴 변경
- 시스템 게시판: /system-boards/{code} → /customer-center/{code}
- 테넌트 게시판: /boards/{code} (변경 없음)

### UI 개선
- 메뉴 목록에서 게시판 메뉴 "📋 게시판" 뱃지 표시
- 게시판 메뉴는 수정/삭제 버튼 숨김 (활성/숨김 토글만 허용)
- 삭제된 게시판 행 클릭 시 404 오류 수정

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 21:54:48 +09:00

153 lines
3.9 KiB
PHP

<?php
namespace App\Models\Boards;
use App\Models\Tenants\Tenant;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* 게시판 모델 (mng용)
*
* @property int $id
* @property int|null $tenant_id
* @property bool $is_system 시스템 게시판 여부
* @property string|null $board_type 게시판 유형
* @property string $board_code 게시판 코드
* @property string $name 게시판명
* @property string|null $description 설명
* @property string $editor_type 에디터 타입
* @property bool $allow_files 파일 첨부 허용
* @property int $max_file_count 최대 파일 수
* @property int $max_file_size 최대 파일 크기 (KB)
* @property array|null $extra_settings 추가 설정
* @property bool $is_active 활성 여부
*/
class Board extends Model
{
use SoftDeletes;
protected $table = 'boards';
protected $fillable = [
'tenant_id',
'is_system',
'board_type',
'board_code',
'name',
'description',
'editor_type',
'allow_files',
'max_file_count',
'max_file_size',
'extra_settings',
'is_active',
'created_by',
'updated_by',
'deleted_by',
];
protected $casts = [
'is_system' => 'boolean',
'is_active' => 'boolean',
'allow_files' => 'boolean',
'extra_settings' => 'array',
];
protected $attributes = [
'is_system' => false,
'is_active' => true,
'allow_files' => true,
'max_file_count' => 5,
'max_file_size' => 20480,
'editor_type' => 'wysiwyg',
];
// =========================================================================
// Scopes
// =========================================================================
/**
* 시스템 게시판만 (mng용)
*/
public function scopeSystemOnly(Builder $query): Builder
{
return $query->where('is_system', true);
}
/**
* 활성 게시판만
*/
public function scopeActive(Builder $query): Builder
{
return $query->where('is_active', true);
}
/**
* 게시판 유형으로 필터링
*/
public function scopeOfType(Builder $query, string $type): Builder
{
return $query->where('board_type', $type);
}
// =========================================================================
// Relationships
// =========================================================================
public function fields(): HasMany
{
return $this->hasMany(BoardSetting::class, 'board_id')
->orderBy('sort_order');
}
public function posts(): HasMany
{
return $this->hasMany(Post::class, 'board_id');
}
public function tenant(): BelongsTo
{
return $this->belongsTo(Tenant::class, 'tenant_id');
}
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
public function updater(): BelongsTo
{
return $this->belongsTo(User::class, 'updated_by');
}
public function deletedByUser(): BelongsTo
{
return $this->belongsTo(User::class, 'deleted_by');
}
// =========================================================================
// Helper Methods
// =========================================================================
/**
* extra_settings에서 특정 키 값 가져오기
*/
public function getSetting(string $key, $default = null)
{
return data_get($this->extra_settings, $key, $default);
}
/**
* 시스템 게시판 여부 확인
*/
public function isSystemBoard(): bool
{
return $this->is_system === true;
}
}