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);
}
}
@endphpTrigger
$this->dispatch('notify', message: 'Saved!', type: 'success');