Home API Tools Posts Hire Me About
Sign In Create Account
Livewire

Building a Todo List with Livewire v4

February 01, 2026 1 min read 20 views

Build a full-featured todo list.

Component

class TodoList extends Component
{
    public string $newTodo = '';
    public array $todos = [];
    
    public function add(): void
    {
        $this->todos[] = ['id' => uniqid(), 'text' => $this->newTodo, 'done' => false];
        $this->newTodo = '';
    }
    
    public function toggle(string $id): void
    {
        foreach ($this->todos as &$t) {
            if ($t['id'] === $id) $t['done'] = !$t['done'];
        }
    }
}
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!