ras/flash-alert-bundle
A PHP package for managing flash alert notifications across requests. It lets you queue success, error, warning, and info messages, then render them with configurable templates and styling in Laravel or Symfony-style applications.
The bundle is Symfony-first, not Laravel: treat it as a drop-in replacement for manually looping over app.flashes in your base layout. Minimal path:
composer require ras/flash-alert-bundle
config/bundles.php:
Ras\FlashAlertBundle\FlashAlertBundle::class => ['all' => true],
Resources/ (or assets/) directory and its DependencyInjection/Configuration.php. That tells you three things you need immediately:
Resources/public/js/...) and how to publish/link it,flash_alert: in config/packages/.templates/base.html.twig): include the JS asset and render the alert mount point just before </body>.// Controller
$this->addFlash('success', 'Saved successfully.');
return $this->redirectToRoute('dashboard');
Then confirm the alert appears on the redirected page — not on the POST response.If nothing appears, you have almost certainly missed step 4 or the flash was consumed on the POST request itself.
Global layout mount (the core pattern). Render the bundle’s container once in base.html.twig, after your JS bundle but before </body>. Keep it out of individual templates; flashes are session-scoped and can appear on any page.
Standard controller flow. Use Symfony’s native addFlash($type, $message) rather than bundle-specific methods unless the README documents otherwise. The bundle is a renderer, not a replacement for the flash bag. Typical types to standardize on: success, error, warning, info.
Mapping types to your CSS. Most flash-alert bundles expose a config or an option to map types to CSS classes. Decide your mapping early (e.g. success → alert-success) and keep it in config/packages/flash_alert.yaml so controllers stay presentation-agnostic.
Multiple flashes in one request. Expect a queue: several addFlash() calls in a single request should render as stacked alerts. Test this explicitly — one alert is the happy path, three is where ordering and auto-dismiss bugs show up.
Auto-dismiss vs. persistent alerts. Use the JS timing option for success/info, but disable auto-dismiss for error so validation messages and failed-payment errors aren’t lost. If the bundle only offers a single global timeout, render errors through your own template and reserve the JS path for transient notices.
Redirect-after-POST is the intended workflow. The pattern the bundle is built around is: flash on POST → 302 → render on GET. Don’t try to render alerts directly into the POST response for form validation failures; use Symfony form errors there and reserve flash alerts for post-redirect outcomes.
Integration with partial navigation. If you use Turbo/Turbolinks/hotwire-style navigation, the JS must initialize on each page swap, not just DOMContentLoaded. Check whether the bundle’s script is idempotent; if not, add a listener for your navigation event that re-runs the initializer.
Testing pattern. In functional tests, assert on $client->getRequest()->getSession()->getFlashBag()->peek('success') before following the redirect, and assert on the rendered container markup after. That separates “flash was set” from “flash was rendered.”
ras/flash-alert-bundle targets Symfony’s Session/FlashBag and Twig. In Laravel, use session()->flash() with your own Blade component instead; do not attempt to install this via Composer into a Laravel app expecting it to work.Resources/public files may not be auto-exposed. Check whether you need assets:install, an Encore addEntry, or an AssetMapper path config. A 404 on the JS file means alerts silently never initialize.raw/html option, treat it as an XSS vector and only use it with trusted, server-generated content.session: false for some routes, flashes won’t persist. Confirm the redirect target shares the same session.composer.json and vendor/copy the JS if you need to patch it, rather than relying on upstream fixes.templates/bundles/FlashAlertBundle/... rather than forking the JS. That keeps upgrades and security patches cheap.How can I help you explore Laravel packages today?