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

Building Notifications with Livewire v4

February 01, 2026 1 min read 32 views

Build a notification system.

Toast Component

@php
new class extends Livewire\Component {
    public array $notifications = [];
    
    #[On('notify')]
    public function add(string $message, string $type = 'info'): void
    {
        $this->notifications[] = ['id' => uniqid(), 'message' => $message, 'type' => $type];
    }
    
    public function remove(string $id): void
    {
        $this->notifications = array_filter($this->notifications, fn($n) => $n['id'] !== $id);
    }
}
@endphp

Trigger

$this->dispatch('notify', message: 'Saved!', type: 'success');
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!