'array', 'created_at' => 'datetime', ]; public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } public static function log(int $userId, string $action, string $description, ?string $targetType = null, ?int $targetId = null, array $metadata = []): self { return static::create([ 'user_id' => $userId, 'action' => $action, 'target_type' => $targetType, 'target_id' => $targetId, 'description' => $description, 'ip_address' => request()->ip() ?? 'unknown', 'metadata' => $metadata, ]); } public static function logLogin(int $userId): self { return self::log($userId, 'login', 'Staff logged into housekeeping', null, null, [ 'browser' => request()->userAgent() ?? 'unknown', ]); } public static function logAction(int $userId, string $action, string $targetType, int $targetId, string $description): self { return self::log($userId, $action, $description, $targetType, $targetId); } public static function getActionIcon(string $action): string { return match ($action) { 'login' => '🔓', 'logout' => '🔒', 'user_ban' => '🚫', 'user_unban' => '✅', 'user_edit' => '✏️', 'user_delete' => '🗑️', 'rank_change' => '⬆️', 'settings_update' => '⚙️', 'content_delete' => '🗑️', 'content_create' => '➕', 'content_edit' => '✏️', default => '📝', }; } public static function getActionColor(string $action): string { return match ($action) { 'login', 'logout' => '#22c55e', 'user_ban', 'content_delete' => '#ef4444', 'user_unban', 'content_create' => '#22c55e', 'user_edit', 'content_edit', 'rank_change' => '#f59e0b', 'settings_update' => '#3b82f6', default => '#9ca3af', }; } }