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.
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.
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.
flasher-toastr.min.js; otherwise, the driver won’t initialize and no messages appear (silent failure).flasher() multiple times on the same request causes duplicates.timeOut: 3000, closeButton: true) in config/flasher.php under toastr.options—don’t call withOptions() repeatedly for static settings.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.php artisan vendor:publish --tag=flasher-views, then edit resources/views/vendor/flasher/toastr.blade.php.session()->flash() alongside flasher()—stick to flasher() consistently to prevent mismatches between storage and rendering.How can I help you explore Laravel packages today?