2025-07-17 10:05:47 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2025-11-06 17:45:49 +09:00
|
|
|
use App\Models\Commons\Menu;
|
2025-08-22 15:57:44 +09:00
|
|
|
use App\Models\Tenants\Tenant;
|
2025-11-06 17:45:49 +09:00
|
|
|
use App\Observers\MenuObserver;
|
2025-08-22 15:57:44 +09:00
|
|
|
use App\Observers\TenantObserver;
|
2025-07-26 14:25:45 +09:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2025-08-14 17:20:28 +09:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2025-11-06 17:45:49 +09:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
2025-07-17 10:05:47 +09:00
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Register any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
2025-08-14 17:20:28 +09:00
|
|
|
// 개발환경 + API 라우트에서만 쿼리 로그 수집
|
|
|
|
|
if (app()->environment('local')) {
|
|
|
|
|
// 콘솔/큐 등 non-HTTP 컨텍스트 보호
|
|
|
|
|
if (function_exists('request') && request() && request()->is('api/*')) {
|
|
|
|
|
DB::enableQueryLog();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-17 10:05:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
2025-08-16 03:25:06 +09:00
|
|
|
// DB::enableQueryLog();
|
2025-11-06 17:45:49 +09:00
|
|
|
Builder::macro('debug', function ($debug = null) {
|
2025-07-26 14:25:45 +09:00
|
|
|
if (is_null($debug) && app()->environment('local')) {
|
|
|
|
|
$debug = true;
|
|
|
|
|
}
|
|
|
|
|
if ($debug) {
|
|
|
|
|
\DB::enableQueryLog();
|
|
|
|
|
}
|
2025-11-06 17:45:49 +09:00
|
|
|
|
2025-07-26 14:25:45 +09:00
|
|
|
return $this;
|
|
|
|
|
});
|
2025-08-16 03:25:06 +09:00
|
|
|
|
|
|
|
|
// 메뉴 생성/수정/삭제 ↔ 권한 자동 동기화
|
|
|
|
|
Menu::observe(MenuObserver::class);
|
2025-08-22 15:57:44 +09:00
|
|
|
|
|
|
|
|
// 테넌트 생성 시 자동 실행
|
|
|
|
|
Tenant::observe(TenantObserver::class);
|
2025-07-17 10:05:47 +09:00
|
|
|
}
|
|
|
|
|
}
|