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

Confirmation Dialogs in Livewire v4

Add confirmation prompts before destructive actions.

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

On this page

  1. Basic Confirmation
  2. Dynamic Confirmation Messages
  3. Component Method

Livewire v4 provides built-in browser confirmation dialogs for destructive actions.

Basic Confirmation

blade
<!-- Simple confirmation before delete -->
<button 
    wire:click="delete" 
    wire:confirm="Are you sure you want to delete this item?"
    class="bg-red-500 text-white px-4 py-2 rounded"
>
    Delete Item
</button>

<!-- Confirmation for any action -->
<button 
    wire:click="resetAll" 
    wire:confirm="This will reset all settings to default. Continue?"
>
    Reset Settings
</button>

Dynamic Confirmation Messages

blade
<!-- Include item name in confirmation -->
@foreach($users as $user)
    <div class="flex justify-between items-center">
        <span>{{ $user->name }}</span>
        <button 
            wire:click="deleteUser({{ $user->id }})" 
            wire:confirm="Are you sure you want to delete {{ $user->name }}? This cannot be undone."
        >
            Delete
        </button>
    </div>
@endforeach

<!-- With count information -->
<button 
    wire:click="deleteSelected" 
    wire:confirm="Delete {{ count($selected) }} selected items?"
>
    Delete Selected ({{ count($selected) }})
</button>

Component Method

php
class UserManager extends Component
{
    public function deleteUser(int $userId): void
    {
        // This only runs if user confirms
        $user = User::findOrFail($userId);
        $user->delete();
        
        session()->flash('message', 'User deleted successfully');
    }
    
    public function deleteSelected(): void
    {
        User::whereIn('id', $this->selected)->delete();
        $this->selected = [];
    }
}
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