From bd8adffb3483110028b5f5074f9797c294faa670 Mon Sep 17 00:00:00 2001 From: kent Date: Sun, 28 Dec 2025 01:42:47 +0900 Subject: [PATCH] =?UTF-8?q?fix(post):=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=B2=A8=EB=B6=80=ED=8C=8C=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: - 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 --- app/Models/Boards/Post.php | 11 +++++++++-- app/Providers/AppServiceProvider.php | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Models/Boards/Post.php b/app/Models/Boards/Post.php index 07778bb..ddadd9a 100644 --- a/app/Models/Boards/Post.php +++ b/app/Models/Boards/Post.php @@ -4,6 +4,7 @@ use App\Models\Commons\File; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** @@ -20,9 +21,15 @@ class Post extends Model 'ip_address', 'is_notice', 'is_secret', 'views', 'status', ]; - public function files() + /** + * 게시글 첨부파일 (document_type/document_id 기반) + * - 시스템 게시판의 경우 tenant 무관하게 조회해야 하므로 TenantScope 제외 + */ + public function files(): HasMany { - return $this->morphMany(File::class, 'fileable'); + return $this->hasMany(File::class, 'document_id') + ->where('document_type', 'post') + ->withoutGlobalScope(\App\Models\Scopes\TenantScope::class); } public function comments() diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index c7be328..755c030 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Models\Boards\Post; use App\Models\Commons\Menu; use App\Models\Members\User; use App\Models\Tenants\Tenant; @@ -33,9 +34,10 @@ public function register(): void */ public function boot(): void { - // Morph Map: mng/api 프로젝트 간 User 모델 경로 통일 + // Morph Map: 다형성 관계 모델 등록 (enforceMorphMap 사용 시 필수) Relation::enforceMorphMap([ 'user' => User::class, + 'post' => Post::class, ]); // DB::enableQueryLog();