bots = Auth::user()->bots; } public function search() { $this->bots = Auth::user()->bots() ->where('name', 'like', '%' . $this->query . '%') ->orWhere('class', 'like', '%' . $this->query . '%') ->get(); } public function toggleBot($botId) { $bot = \App\Models\Bot::find($botId); if ($bot) { $bot->enabled = !$bot->enabled; $bot->save(); $this->bots = \App\Models\Bot::all(); // Refresh the list flash()->success("Bot '{$bot->name}' has been " . ($bot->enabled ? 'enabled' : 'disabled') . "."); } } public function deleteBot(int $botId): void { $bot = \App\Models\Bot::find($botId); if ($bot) { LivewireAlert::title('Are you sure you want to delete ' . $bot->name . '?') ->asConfirm() ->onConfirm('confirmDelete', [$bot]) ->show(); } } public function confirmDelete(Bot $bot): void { $bot->delete(); $this->bots = \App\Models\Bot::all(); // Refresh the list flash()->success("Bot '{$bot->name}' has been deleted."); } public function runBot($botId) { $bot = \App\Models\Bot::find($botId); if ($bot) { LivewireAlert::title('Are you sure you want to run ' . $bot->name . '?') ->asConfirm() ->onConfirm('confirmRunBot', [$bot]) ->show(); } } public function confirmRunBot(Bot $bot): void { $log = $bot->logs()->create([ 'status' => 'pending', 'started_at' => now(), ]); // Dispatch the job to run the bot dispatch(new RunBot($bot, $log)); flash()->success("Bot '{$bot->name}' is being executed."); } public function render() { return view('livewire.bots-list'); } }