| Install | |
|---|---|
composer require thbappy7706/laravel-toastify |
|
| Latest Version: | v1.1.3 |
| PHP: | ^8.1|^8.2|^8.3|^8.4 |
A feature-rich, customizable toast notification package for Laravel Blade and Livewire v3/v4, inspired by react-toastify. Includes beautiful bouncing animations and extensive customization options.
✨ Multiple Animations: Bounce (default), Slide, Zoom, Flip
🎯 Flexible Positioning: 6 positions (top-left, top-right, top-center, bottom-left, bottom-right, bottom-center)
🎨 Toast Types: Success, Error, Warning, Info, Default
⏱️ Auto-close: Customizable duration or disable
📊 Progress Bar: Visual countdown timer
🖱️ Drag to Dismiss: Swipe or drag toasts away
⏸️ Pause on Hover: Auto-pause timer when hovering
🌙 Multiple Themes: Light, Dark, Colored
🌍 RTL Support: Right-to-left text direction
📱 Responsive: Mobile-friendly
⚡ Livewire v3/v4 Compatible: Real-time updates
🎭 Stackable: Multiple toasts display beautifully
composer require thbappy7706/laravel-toastify
php artisan vendor:publish --tag=toastify-config
php artisan vendor:publish --tag=toastify-views
php artisan vendor:publish --tag=toastify-assets
Add the Livewire component to your layout file (usually resources/views/layouts/app.blade.php):
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Your head content -->
@stack('styles')
</head>
<body>
{{ $slot }}
<!-- Add Toastify Container -->
<livewire:toastify-container />
@stack('scripts')
</body>
</html>
Use the Blade directive in your layout:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Your head content -->
@stack('styles')
</head>
<body>
@yield('content')
<!-- Add Toastify Container -->
@toastify
@stack('scripts')
</body>
</html>
use Toastify\Laravel\Facades\Toastify;
public function store(Request $request)
{
// Your logic here
Toastify::success('User created successfully!');
return redirect()->route('users.index');
}
// Other types
Toastify::error('Something went wrong!');
Toastify::warning('Please check your input!');
Toastify::info('New update available!');
Toastify::default('This is a toast message');
use Toastify\Laravel\Facades\Toastify;
class UserForm extends Component
{
public function save()
{
// Your logic here
$this->dispatch('toast:add', toast: [
'type' => 'success',
'message' => 'Data saved successfully!'
]);
}
}
// Success toast
window.toastify.success('Operation successful!');
// Error toast
window.toastify.error('Operation failed!');
// Warning toast
window.toastify.warning('Please be careful!');
// Info toast
window.toastify.info('Did you know?');
// Default toast
window.toastify.default('Hello World!');
Toastify::success('Custom toast!', [
'autoClose' => 3000, // Auto close after 3 seconds
'position' => 'bottom-right', // Position
'transition' => 'slide', // Animation type
'hideProgressBar' => false, // Show progress bar
'pauseOnHover' => true, // Pause on hover
'draggable' => true, // Enable drag to dismiss
'closeButton' => true, // Show close button
'rtl' => false, // Right-to-left
]);
| Option | Type | Default | Description |
|---|---|---|---|
autoClose |
int/false | 5000 | Auto close duration in ms (false to disable) |
position |
string | 'top-right' | Position of toast |
transition |
string | 'bounce' | Animation type (bounce, slide, zoom, flip) |
hideProgressBar |
bool | false | Hide the progress bar |
closeButton |
bool | true | Show close button |
pauseOnHover |
bool | true | Pause timer on hover |
pauseOnFocusLoss |
bool | true | Pause when window loses focus |
draggable |
bool | true | Enable drag to dismiss |
draggablePercent |
int | 80 | Percentage of width to dismiss |
rtl |
bool | false | Right-to-left direction |
top-lefttop-centertop-rightbottom-leftbottom-centerbottom-rightbounce - Bouncing effect (default)slide - Sliding effectzoom - Zoom in/out effectflip - Flipping effectsuccess - Green toast with checkmark iconerror - Red toast with error iconwarning - Yellow toast with warning iconinfo - Blue toast with info icondefault - White toast without iconYou can customize the container globally:
<livewire:toastify-container
position="top-right"
transition="bounce"
:newestOnTop="true"
:rtl="false"
/>
// From JavaScript
window.Livewire.dispatch('toast:remove', { id: 'toast_id_here' });
// From JavaScript
window.Livewire.dispatch('toast:clear');
// From PHP
Toastify::clear();
The configuration file is located at config/toastify.php:
return [
'position' => env('TOASTIFY_POSITION', 'top-right'),
'transition' => env('TOASTIFY_TRANSITION', 'bounce'),
'autoClose' => env('TOASTIFY_AUTO_CLOSE', 5000),
'hideProgressBar' => env('TOASTIFY_HIDE_PROGRESS_BAR', false),
'closeButton' => env('TOASTIFY_CLOSE_BUTTON', true),
'pauseOnHover' => env('TOASTIFY_PAUSE_ON_HOVER', true),
'pauseOnFocusLoss' => env('TOASTIFY_PAUSE_ON_FOCUS_LOSS', true),
'draggable' => env('TOASTIFY_DRAGGABLE', true),
'draggablePercent' => env('TOASTIFY_DRAGGABLE_PERCENT', 80),
'rtl' => env('TOASTIFY_RTL', false),
'newestOnTop' => env('TOASTIFY_NEWEST_ON_TOP', true),
'theme' => env('TOASTIFY_THEME', 'light'),
];
You can set defaults in your .env file:
TOASTIFY_POSITION=top-right
TOASTIFY_TRANSITION=bounce
TOASTIFY_AUTO_CLOSE=5000
TOASTIFY_THEME=light
TOASTIFY_DRAGGABLE=true
Available themes:
light - Light background (default)dark - Dark backgroundcolored - Background matches toast type colorChange theme in config:
'theme' => 'dark',
You can customize the CSS by editing the published CSS file at public/vendor/toastify/css/toastify.css or by overriding CSS variables:
:root {
--toastify-color-success: #10b981;
--toastify-color-error: #ef4444;
--toastify-color-warning: #f59e0b;
--toastify-color-info: #3b82f6;
--toastify-toast-width: 350px;
--toastify-z-index: 9999;
}
Toastify::success('Profile updated successfully!');
Toastify::error('Failed to save data!', [
'autoClose' => 8000, // 8 seconds
]);
Toastify::warning('Your session will expire soon!', [
'position' => 'bottom-center',
'autoClose' => false, // Don't auto close
]);
Toastify::info('Check out our new features!', [
'transition' => 'slide',
'position' => 'top-left',
]);
Toastify::success('Item 1 added!');
Toastify::success('Item 2 added!');
Toastify::info('Cart updated!');
Toastify::success('تم الحفظ بنجاح!', [
'rtl' => true,
]);
Inspired by react-toastify by Fadi Khadra.
The MIT License (MIT). Please see License File for more information.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please file an issue on the GitHub repository.