Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Toastr Laravel Package

yoeunes/toastr

Laravel toast notifications powered by toastr.js via PHPFlasher. Install with Composer and publish assets, then trigger info/success/warning/error messages using the flash()/toastr() helper in controllers for quick user feedback.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package with composer require yoeunes/toastr.
  2. Publish assets using php artisan flasher:install. This installs the necessary JavaScript/CSS (via PHPFlasher’s flasher-toastr-laravel integration) into your public/ directory.
  3. Start using it in controllers: call toastr()->success('...'), error(), warning(), or info() before a redirect or response.
  4. Ensure your main layout (e.g., resources/views/layouts/app.blade.php) includes {{ flasher()->render() }} after </html> or before closing </body> — this renders the toasts and scripts.

Implementation Patterns

  • Controller-Level Notifications: Use toastr() (or flash()->toastr(), both work) right before redirects. Ideal for CRUD operations: success after create/update, errors on failure.
  • Bulk Notifications: Chain multiple calls (e.g., toastr()->success('Saved')->warning('Retry count reset')), though avoid overuse per request.
  • Custom Config via Flasher: Use flasher()->addOptions(['positionClass' => 'toast-bottom-right']) or config via config/flasher.php (published during flasher:install). The config mirrors PHPFlasher options, including global settings like timeout, closeButton, progressBar.
  • Async Support: Works seamlessly with Laravel’s Livewire (call toastr() in event methods) and Filament actions/resources out of the box.
  • Testing Helpers: In tests, use flasher()->getMessages() to assert toast presence/absence after a request.

Gotchas and Tips

  • Positioning Quirk: Default positionClass is 'toast-top-right'. Change globally in config/flasher.php or use toastr()->position('toast-bottom-left') per-message.
  • Blade Rendering Order: If {{ flasher()->render() }} is placed before </html>, JS/CSS may load after the DOM, causing timing issues. Move it inside <body>, just before </body>, for reliable toast display.
  • Version 3 Depends on PHPFlasher: You no longer install toastr.js manually — it’s bundled automatically. Avoid mixing with direct toastr CDN scripts to prevent conflicts.
  • Debugging Missing Toasts:
    • Confirm flasher.js and flasher.css are served (check DevTools Network tab after redirect).
    • Ensure toastr JavaScript is loaded (global toastr object should exist in console).
    • Check session('flash_messages') isn’t cleared too early (e.g., by middleware redirects before response).
  • Extending Functionality: Override PHPFlasher services via Laravel’s service provider bindings, or use flasher()->template('my-template') for custom toast markup (if needed via PHPFlasher extension).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4