'array', 'is_default' => 'boolean', ]; /** * 민감 정보 숨김 */ protected $hidden = [ 'api_key', 'auth_token', ]; /** * 사용자 관계 */ public function user(): BelongsTo { return $this->belongsTo(User::class); } /** * API Key 암호화 저장 */ public function setApiKeyAttribute(?string $value): void { if ($value && config('api-explorer.security.encrypt_tokens', true)) { $this->attributes['api_key'] = Crypt::encryptString($value); } else { $this->attributes['api_key'] = $value; } } /** * API Key 복호화 조회 */ public function getDecryptedApiKeyAttribute(): ?string { if (! $this->attributes['api_key']) { return null; } if (config('api-explorer.security.encrypt_tokens', true)) { try { return Crypt::decryptString($this->attributes['api_key']); } catch (\Exception $e) { return $this->attributes['api_key']; } } return $this->attributes['api_key']; } /** * Auth Token 암호화 저장 */ public function setAuthTokenAttribute(?string $value): void { if ($value && config('api-explorer.security.encrypt_tokens', true)) { $this->attributes['auth_token'] = Crypt::encryptString($value); } else { $this->attributes['auth_token'] = $value; } } /** * Auth Token 복호화 조회 */ public function getDecryptedAuthTokenAttribute(): ?string { if (! $this->attributes['auth_token']) { return null; } if (config('api-explorer.security.encrypt_tokens', true)) { try { return Crypt::decryptString($this->attributes['auth_token']); } catch (\Exception $e) { return $this->attributes['auth_token']; } } return $this->attributes['auth_token']; } /** * 기본 환경 스코프 */ public function scopeDefault($query) { return $query->where('is_default', true); } }