문제: - 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>
62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Models\Boards\Post;
|
|
use App\Models\Commons\Menu;
|
|
use App\Models\Members\User;
|
|
use App\Models\Tenants\Tenant;
|
|
use App\Observers\MenuObserver;
|
|
use App\Observers\TenantObserver;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
// 개발환경 + API 라우트에서만 쿼리 로그 수집
|
|
if (app()->environment('local')) {
|
|
// 콘솔/큐 등 non-HTTP 컨텍스트 보호
|
|
if (function_exists('request') && request() && request()->is('api/*')) {
|
|
DB::enableQueryLog();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// Morph Map: 다형성 관계 모델 등록 (enforceMorphMap 사용 시 필수)
|
|
Relation::enforceMorphMap([
|
|
'user' => User::class,
|
|
'post' => Post::class,
|
|
]);
|
|
|
|
// DB::enableQueryLog();
|
|
Builder::macro('debug', function ($debug = null) {
|
|
if (is_null($debug) && app()->environment('local')) {
|
|
$debug = true;
|
|
}
|
|
if ($debug) {
|
|
\DB::enableQueryLog();
|
|
}
|
|
|
|
return $this;
|
|
});
|
|
|
|
// 메뉴 생성/수정/삭제 ↔ 권한 자동 동기화
|
|
Menu::observe(MenuObserver::class);
|
|
|
|
// 테넌트 생성 시 자동 실행
|
|
Tenant::observe(TenantObserver::class);
|
|
}
|
|
}
|