Livewire

Building a Tag Input with Livewire v4

February 01, 2026 1 min read 10 views

Build a tag input component.

Component

@php
new class extends Livewire\Component {
    public array $tags = [];
    public string $newTag = '';
    
    public function addTag(): void
    {
        if (trim($this->newTag) && !in_array($this->newTag, $this->tags)) {
            $this->tags[] = $this->newTag;
        }
        $this->newTag = '';
    }
    
    public function removeTag(int $index): void
    {
        unset($this->tags[$index]);
        $this->tags = array_values($this->tags);
    }
}
@endphp
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!