- AppServiceProvider에 Relation::enforceMorphMap 설정 추가 - tokenable_type을 'user' 별칭으로 통일 - mng에서 생성한 토큰을 api에서 사용 시 500 에러 해결 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
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: mng/api 프로젝트 간 User 모델 경로 통일
|
|
Relation::enforceMorphMap([
|
|
'user' => User::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);
|
|
}
|
|
}
|