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

Flasher Toastr Laravel Package

php-flasher/flasher-toastr

Laravel adapter for Toastr notifications using PHP Flasher. Quickly flash success/error/info messages to the session and render them as Toastr popups in your views, with configurable options and seamless integration with flasherphp/flasher.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package via Composer: composer require php-flasher/flasher-toastr. Laravel will auto-discover the service provider—no manual registration needed. Next, include Toastr and Flasher assets in your Blade layout (typically in resources/views/layouts/app.blade.php): load toastr.min.css in <head>, and toastr.min.js + flasher-toastr.min.js before </body>. Your first notification is as simple as calling flasher()->addSuccess('Message saved!'); in a controller—then redirect so the flash persists in the session. Check config/flasher.php for default options and verify the published config matches your Toastr theme.

Implementation Patterns

Use flasher() helper before redirects in controllers for clean separation of concerns—messages are stored in the session and auto-rendered on the next request. Prefer semantic methods like addSuccess(), addError(), addWarning(), and addInfo() for readability and semantic intent. For per-message customization, chain withOptions() or withPosition() (e.g., ->withPosition('toast-bottom-left')). In API contexts, use response()->json(...)->withFlasher('success', 'Operation completed') to inject notifications alongside JSON payloads. In Blade, always include @flasher once in your main layout—this renders all queued messages. For SPA-like flows (non-redirects), consider AJAX calls with fetch() that trigger JS-side toastr manually, but avoid mixing session and JS-triggered notifications to prevent duplicates.

Gotchas and Tips

  • Asset loading order is critical: Toastr JS must load before flasher-toastr.min.js; otherwise, the driver won’t initialize and no messages appear (silent failure).
  • Session flash lifecycle: Laravel’s session flash data only lasts one request—always redirect after setting flash messages; otherwise, calling flasher() multiple times on the same request causes duplicates.
  • Config overrides: Set global defaults (e.g., timeOut: 3000, closeButton: true) in config/flasher.php under toastr.options—don’t call withOptions() repeatedly for static settings.
  • Silent failures: If messages don’t appear, inspect browser DevTools for toastr is not defined. Missing assets (especially from public/vendor/) are the usual culprit—verify php artisan vendor:publish ran and npm run dev compiled assets if using Elixir/Vite.
  • Blade template overrides: If you need custom HTML (e.g., icons, links), publish the default view via php artisan vendor:publish --tag=flasher-views, then edit resources/views/vendor/flasher/toastr.blade.php.
  • Avoid native Laravel session helpers: Don’t use session()->flash() alongside flasher()—stick to flasher() consistently to prevent mismatches between storage and rendering.
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
milesj/emojibase
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