<x-button x-on:click="Toaster.success('Toast from frontend!')">Frontend</x-button>
Toaster
facade. The toaster also
persisted so the toast will be shown even after navigating to another page.
+use Masmerise\Toaster\Toaster; use Livewire\Component; class YourComponent extends Component { public function toast(): void {+ Toaster::success('Toast from backend!'); } }
<x-button wire:click="toast">Backend</x-button>
success
,
info
,
warning
, and
error
.
<x-button x-on:click="Toaster.success('Success toast!')">Success</x-button><x-button x-on:click="Toaster.info('Info toast!')">Info</x-button><x-button x-on:click="Toaster.warning('Warning toast!')">Warning</x-button><x-button x-on:click="Toaster.error('Error toast!')">Error</x-button>
3
seconds, but it can be customized by passing the
duration in milliseconds or change the default duration in the configuration file.
+use Masmerise\Toaster\Toaster; use Livewire\Component; class YourComponent extends Component { public function toast3Seconds() {+ Toaster::info('This toast will disappear in 3 seconds!'); } public function toast6Seconds() {+ Toaster::info('This toast will disappear in 6 seconds!') + ->duration(6000); } public function toast9Seconds() {+ Toaster::info('This toast will disappear in 9 seconds!') + ->duration(9000); } }
<x-button wire:click="toast3Seconds">3s</x-button><x-button wire:click="toast6Seconds">6s</x-button><x-button wire:click="toast9Seconds">9s</x-button>
/config/toaster.php
. Here is the recommended
configuration for the toaster.
return [ 'accessibility' => true, 'alignment' => 'bottom', 'closeable' => true, 'duration' => 3000, 'position' => 'right', - 'replace' => false, + 'replace' => true, - 'suppress' => false, + 'suppress' => true, 'translate' => true, ];