문제: - morphMany 사용 시 "No morph map defined" 에러 발생 - 시스템 게시판 파일 조회 시 tenant_id 불일치로 빈 배열 반환 해결: - AppServiceProvider: Post 모델을 enforceMorphMap에 등록 - Post::files(): morphMany → hasMany(document_type/document_id 기반)로 변경 - Post::files(): TenantScope 제외하여 시스템 게시판 파일 조회 가능 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Boards;
|
|
|
|
use App\Models\Commons\File;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* @mixin IdeHelperPost
|
|
*/
|
|
class Post extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'posts';
|
|
|
|
protected $fillable = [
|
|
'tenant_id', 'board_id', 'user_id', 'title', 'content', 'editor_type',
|
|
'ip_address', 'is_notice', 'is_secret', 'views', 'status',
|
|
];
|
|
|
|
/**
|
|
* 게시글 첨부파일 (document_type/document_id 기반)
|
|
* - 시스템 게시판의 경우 tenant 무관하게 조회해야 하므로 TenantScope 제외
|
|
*/
|
|
public function files(): HasMany
|
|
{
|
|
return $this->hasMany(File::class, 'document_id')
|
|
->where('document_type', 'post')
|
|
->withoutGlobalScope(\App\Models\Scopes\TenantScope::class);
|
|
}
|
|
|
|
public function comments()
|
|
{
|
|
return $this->hasMany(BoardComment::class, 'post_id')->whereNull('parent_id')->where('status', 'active');
|
|
}
|
|
|
|
public function board()
|
|
{
|
|
return $this->belongsTo(Board::class, 'board_id');
|
|
}
|
|
}
|