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();