'boolean', 'last_used_at' => 'datetime', 'last_tested_at' => 'datetime', ]; // Automatic encryption for API keys public function setApiKeyAttribute($value): void { $this->attributes['api_key'] = Crypt::encryptString($value); } public function getApiKeyAttribute($value): string { return Crypt::decryptString($value); } // Relationships public function gatewayUser() { return $this->belongsTo(GatewayUser::class, 'gateway_user_id', 'user_id'); } // Helper methods public function markAsUsed(): void { $this->update(['last_used_at' => now()]); } public function markAsTested(bool $success, ?string $error = null): void { $this->update([ 'last_tested_at' => now(), 'test_status' => $success ? 'success' : 'failed', 'test_error' => $error, ]); } }