bpocallaghan/alert
Laravel package for easy flash alerts: set success, error, warning, or info messages in controllers, then render them in Blade views with included alert partials. Provides consistent, customizable, dismissible Bootstrap-style notifications, with simple setup for quick integration in your app.
Install via Composer:
composer require bpocallaghan/alert
On Laravel 5.5+ the service provider and Alert facade alias are auto-discovered. On older versions, register Bpocallaghan\Alert\AlertServiceProvider in config/app.php and add the alias:
'Alert' => Bpocallaghan\Alert\Facades\Alert::class,
In a controller, flash a message before redirecting:
public function store(Request $request)
{
// ... persist
alert()->success('Record saved successfully.');
return redirect()->route('records.index');
}
In your layout, render the alerts exactly once — typically just inside the container near the top of the body:
{!! Alert::render() !!}
Where to look first after install:
vendor/bpocallaghan/alert/src/ — the main Alert class for the public API and the Blade view used for rendering.php artisan vendor:publish --provider="Bpocallaghan\Alert\AlertServiceProvider") — session key, view path, and any defaults.The first real use case is the classic post-redirect-get flow: validate, persist, flash, redirect, and let the layout render the message on the next request.
Helper vs. Facade. Both are first-class; pick one per codebase and stick to it.
alert()->success('Saved.');
Alert::error('Something went wrong.');
Message types. The conventional four map to Bootstrap contextual classes:
alert()->success('...');
alert()->info('...');
alert()->warning('...');
alert()->error('...'); // usually maps to Bootstrap "danger"
Some versions accept a title as a second argument — check the signature in src/Alert.php before relying on it:
alert()->success('Your changes have been saved.', 'Success');
Service-layer flashing. Rather than scattering alert() calls through controllers, flash from the place that knows the outcome and keep controllers thin:
class RecordService
{
public function create(array $data): Record
{
$record = Record::create($data);
alert()->success('Record created.');
return $record;
}
}
Be careful with this once you add queue jobs or API endpoints — flashing to the session in a queued context does nothing useful.
Rendering location. Render in the app layout, not in individual views, so every page inherits alerts. If you use multiple layouts (admin, auth, public), add {!! Alert::render() !!} to each one. Alternatively, include the package view directly if you prefer the include-style:
@include('alert::alert')
Custom markup. The fastest way to support Bootstrap 4/5, Tailwind, or your own design system is to copy the package view into resources/views/vendor/alert/ and point the config at it, or to override the view entirely. Keep the session data contract intact (type + message) and change only the markup.
Multiple alerts in one request. Check whether the underlying implementation appends to an array or overwrites a single entry. If it overwrites, wrap your own thin layer:
Alert::success('First');
Alert::info('Second');
and confirm both render — otherwise flash an array manually under your own session key.
Validation feedback. For form flows, prefer Laravel's built-in $errors bag for field-level errors and reserve this package for the human-readable summary ("Please fix the highlighted fields."). Don't duplicate the same message in both systems.
API / Livewire. Session flashing does not travel to JSON responses. For Inertia or Livewire, either read the flashed key from the shared props/session, or skip this package and return the message in the response payload.
{!! Alert::render() !!} in the layout that the current view extends.{!! !!} is required for the alert HTML, which means a user-supplied message passed straight through is an XSS vector. Escape or sanitize anything derived from user input before flashing.alert-danger is still fine but dismissible markup changed (data-bs-dismiss vs data-dismiss). Override the view rather than patching vendor files.php artisan config:clear in development and config:cache in deploy. A stale cached config pointing at the old view path produces confusing "view not found" errors.array driver (common in some test setups) nothing survives the redirect. Use file, database, or redis for real flash behavior, and assert on the session key in feature tests rather than on rendered HTML.session()->get('alert') (or whatever key is defined in the config) right before the redirect and again in the receiving request. That isolates whether the problem is flashing or rendering.alert()->danger(), alert()->primary()). Avoid editing vendor/ directly — you'll lose changes on composer update.composer.json constraints in the package rather than assuming compatibility with the newest Laravel major.How can I help you explore Laravel packages today?