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

Livewire v4 with Alpine.js Integration

Combine Livewire with Alpine.js for enhanced interactivity.

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

On this page

  1. Access $wire Object
  2. Entangle - Two-Way Binding
  3. Dispatch Events

Livewire v4 works seamlessly with Alpine.js for client-side interactivity.

Access $wire Object

blade
<div x-data="{ loading: false }">
    <!-- Call Livewire methods -->
    <button x-on:click="loading = true; $wire.save().then(() => loading = false)">
        <span x-show="!loading">Save</span>
        <span x-show="loading">Saving...</span>
    </button>
    
    <!-- Access Livewire properties -->
    <span x-text="$wire.username"></span>
    <span x-text="$wire.user.name"></span>
    
    <!-- Set properties -->
    <button x-on:click="$wire.set('total', $wire.total + 1)">Increment</button>
</div>

Entangle - Two-Way Binding

blade
<div x-data="{ 
    open: $wire.entangle('showModal'),
    search: $wire.entangle('searchQuery').live
}">
    <!-- Alpine changes sync to Livewire -->
    <button x-on:click="open = !open">Toggle Modal</button>
    
    <!-- .live modifier for instant sync -->
    <input x-model="search" placeholder="Search...">
    
    <div x-show="open" x-transition>
        Modal content here
    </div>
</div>

Dispatch Events

blade
<div x-data>
    <!-- Dispatch to Livewire from Alpine -->
    <button x-on:click="$wire.dispatch('item-selected', { id: 5 })">
        Select Item
    </button>
    
    <!-- Listen to Livewire events in Alpine -->
    <div x-on:item-saved.window="alert('Saved!')"></div>
</div>
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