Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Livewire

Building a Tag Input with Livewire v4

Create a dynamic tag input component.

1 February 20261 min readLivewireاقرأ بالعربية

On this page

  1. Component

Build a tag input component.

Component

php
@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
All articles

Keep reading

  • Authorization in Livewire v4 Components1 February 20261 min read
  • Blaze Pre-Compiler: Massive Performance Gains in Livewire v41 February 20261 min read
  • Building a Bookmark Feature with Livewire v41 February 20261 min read