Download the PHP package haxneeraj/laravel-livewire4-toaster without Composer
On this page you can find all versions of the php package haxneeraj/laravel-livewire4-toaster. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download haxneeraj/laravel-livewire4-toaster
More information about haxneeraj/laravel-livewire4-toaster
Files in haxneeraj/laravel-livewire4-toaster
Package laravel-livewire4-toaster
Short Description Elegant toast notifications for Laravel Livewire 4 + Alpine.js โ event-driven, configurable, zero dependencies.
License MIT
Homepage https://github.com/haxneeraj/livewire4-toaster
Informations about the package laravel-livewire4-toaster
๐ Livewire4 Toaster
Elegant toast notifications for Laravel Livewire 4 + Alpine.js โ event-driven, configurable, zero external dependencies.
๐ธ Demo
โจ Features
- Trait-based API โ
$this->success('Saved!')in any Livewire component - Facade & Helper โ
Toast::error('Failed!')ortoast('success', 'Done')from controllers - Event-driven โ Livewire 4
dispatch()โ Alpinex-on:toast.window - Auto-dismiss with animated progress bar & pause-on-hover
- Queue mode โ show one toast at a time with automatic queue
- Duplicate handling โ suppress or replace identical toasts
- Configurable positions โ top-right, top-left, bottom-right, bottom-left, top-center, bottom-center
- Dark mode ready with Tailwind CSS
- Accessible โ
role="status",aria-live="polite" - Redirect support โ flash toasts to session, inject on next page load
- JavaScript API โ
window.Toast.success('Hello!')for frontend-only toasts - Publishable config & views โ full control when you need it
- Zero external dependencies โ no toastr.js, no notyf, just Alpine.js
๐ฆ Installation
1. Install via Composer
The package auto-discovers its service provider and facade.
2. Publish Config (Optional)
This creates config/toaster.php where you can customize everything.
3. Add the Toast Hub to Your Layout
Place the toast-hub component in your main layout file, typically before </body>:
That's it! You're ready to toast. ๐
๐ Usage
In Livewire Components (Toastable Trait)
The Toastable trait is the primary API for Livewire components:
In Controllers (Toast Facade)
Use the Toast facade for controller-based workflows:
Note: When using the facade with redirects, register the
InjectToastsmiddleware (see Middleware Setup).
Global Helper Function
From JavaScript
Include resources/js/toast.js in your build, or use the global window.Toast object (available when the hub is loaded):
Or dispatch a raw event:
In Alpine.js
โ๏ธ Configuration
Publish the config file:
Configuration Reference
| Key | Type | Default | Description |
|---|---|---|---|
position |
string |
"top-right" |
Toast position. Options: top-right, top-left, bottom-right, bottom-left, top-center, bottom-center |
duration |
int |
3000 |
Auto-dismiss time in ms. 0 = sticky (manual dismiss only) |
closable |
bool |
true |
Show close (ร) button |
close_on_click |
bool |
true |
Click anywhere on toast to dismiss |
pause_on_hover |
bool |
true |
Pause auto-dismiss when hovering |
max_toasts |
int |
5 |
Max visible toasts. 0 = unlimited |
queue |
bool |
false |
Queue mode: show one at a time |
suppress_duplicates |
bool |
false |
Ignore duplicate type+message |
replace_duplicates |
bool |
false |
Replace existing duplicate |
show_icon |
bool |
true |
Show type-specific icon |
show_progress_bar |
bool |
true |
Show animated progress bar |
event_name |
string |
"toast" |
Browser event name |
styles |
array |
see below | Per-type Tailwind CSS classes |
Style Configuration
Each toast type has customizable Tailwind classes:
๐ง Middleware Setup
To use the Toast facade or toast() helper in controllers (especially with redirects), register the InjectToasts middleware.
Laravel 11+ (bootstrap/app.php)
Laravel 10 (app/Http/Kernel.php)
The middleware:
- Collects pending toasts from
ToastManagerand session flash - Injects a
<script>tag before</body>that dispatcheswindowevents - The Alpine toast-hub catches these events and renders the toasts
๐จ Customizing Views
Publish the views to fully customize the toast markup:
This copies the Blade component to resources/views/vendor/livewire-toaster/.
Tailwind CSS Purge
Add the package views to your Tailwind content paths:
๐งช Testing
Running Tests
Testing Your Toasts
When testing Livewire components that use the Toastable trait:
When testing controllers that use the facade:
๐ API Reference
Toastable Trait Methods
| Method | Signature | Description |
|---|---|---|
success() |
success(string $message, ?string $title = null, array $options = []) |
Green success toast |
error() |
error(string $message, ?string $title = null, array $options = []) |
Red error toast |
info() |
info(string $message, ?string $title = null, array $options = []) |
Blue info toast |
warning() |
warning(string $message, ?string $title = null, array $options = []) |
Amber warning toast |
toast() |
toast(string $type, string $message, ?string $title = null, array $options = []) |
Generic toast |
Toast Facade / Manager Methods
Same methods as above, plus:
| Method | Description |
|---|---|
toArray() |
Get all pending toasts |
flush() |
Get and clear pending toasts |
flashToSession() |
Flash toasts to session (for redirects) |
hasPending() |
Check if toasts are queued |
count() |
Count pending toasts |
Per-Toast Options
Pass as the $options array:
๐ Package Structure
๐ค Contributing
Contributions are welcome! Please:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing) - Open a Pull Request
Please ensure tests pass (vendor/bin/phpunit) and follow PSR-12 coding standards.
๐ License
The MIT License (MIT). See LICENSE for details.
๐ Credits
- Neeraj Saini (HaxNeeraj) โ Creator & Maintainer
- Built for the TALL Stack community
All versions of laravel-livewire4-toaster with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/contracts Version ^10.0|^11.0|^12.0