'array', 'models' => 'array', 'metadata' => 'array', 'expires' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Get masked version of the key */ public function getMaskedKeyAttribute(): string { return substr($this->token, 0, 8) . '...' . substr($this->token, -4); } /** * Check if key is active (not explicitly marked inactive) */ public function getIsActiveAttribute(): bool { // For now, consider all keys active unless explicitly deleted return true; } /** * Check if key is expired */ public function getIsExpiredAttribute(): bool { if (!$this->expires) { return false; } return $this->expires->isPast(); } /** * Get last used at timestamp */ public function getLastUsedAtAttribute() { $latestLog = $this->usageLogs()->latest('timestamp')->first(); return $latestLog ? $latestLog->timestamp : null; } public function gatewayUser() { return $this->belongsTo(GatewayUser::class, 'user_id', 'user_id'); } // Alias for backwards compatibility public function user() { return $this->gatewayUser(); } public function usageLogs() { return $this->hasMany(UsageLog::class, 'api_key', 'token'); } }