tenantIdOrNull(); if (! $id) { // ko/error.php 의 'tenant_id' 키 사용 throw new BadRequestHttpException(__('error.tenant_id')); } return $id; } /** (선택) API 사용자 ID 필요할 때 401로 던지고 싶다면 */ protected function apiUserId(): int { $uid = app('api_user'); if (! $uid) { // Handler에서 AuthenticationException은 401로 처리 중 throw new AuthenticationException(__('auth.unauthenticated')); } return (int) $uid; } /** * 서비스 컨텍스트 설정 (다른 서비스에서 호출 시 사용) * tenant_id, api_user를 명시적으로 설정 */ public function setContext(int $tenantId, int $userId): self { app()->instance('tenant_id', $tenantId); app()->instance('api_user', $userId); return $this; } }