php-flasher/flasher-toastr-laravel
Laravel integration for php-flasher Toastr notifications. Quickly flash success, error, info, and warning messages to the browser using the Toastr JavaScript library, with simple configuration and support for Laravel’s session-based flashing.
composer require php-flasher/flasher-toastr-laravel — no additional steps needed for Laravel 5.5+ due to auto-discovery.{{ flasher_css() }} in <head> and {{ flasher_js() }} before closing </body> in your main Blade template (or layout partial).flasher()->addSuccess('Welcome back!') — messages are automatically flashed to session and rendered on next page load.with('flasher', ...) to preserve toast data across redirects:
return redirect()->route('users.index')
->with('flasher', [
'type' => 'success',
'message' => 'User created.',
'title' => 'Done'
]);
flasher()->addError('Invalid token.', [
'closeButton' => true,
'positionClass' => 'toast-bottom-full-width'
]);
session()->flash('flasher', [
['message' => 'First alert', 'type' => 'info'],
['message' => 'Second alert', 'type' => 'warning', 'timeOut' => 5000]
]);
config/flasher.php (publish with php artisan vendor:publish --provider="Flasher\Toastr\Laravel\FlasherToastrServiceProvider").Flasher\Toastr\Laravel\FlasherMiddleware is registered in app/Http/Kernel.php under $middlewareGroups['web'] — without it, flashed messages vanish silently on redirects.flasher_js() injects Toastr after jQuery — if you manually include jQuery elsewhere, ensure it loads before flasher_js() to prevent toastr is not defined errors.flasher()->addSuccess('') renders no toast (Toastr behavior), but no error is thrown — validate message content before dispatching.classList in config to override Toastr’s default classes:
'toastr' => [
'classList' => [
'success' => 'bg-green-100 text-green-800 border border-green-300',
'error' => 'bg-red-100 text-red-800 border border-red-300'
]
]
window.Flasher && window.Flasher.render() manually after DOM changes to re-trigger pending toasts.How can I help you explore Laravel packages today?