bot_id); $log = BotLog::findOrFail($this->log_id); $log->update([ 'status' => 'running', ]); try { $class = new $bot->class($bot->config ?? []); $result = $class->run(); // Update the log entry on success $log->update([ 'finished_at' => now(), 'status' => 'success', 'output' => is_string($result) ? $result : json_encode($result, JSON_PRETTY_PRINT), ]); } catch (\Throwable $e) { // Log the error in the bot log $log->update([ 'finished_at' => now(), 'status' => 'failed', 'error' => $e->getMessage(), ]); } } }