Flasher
Show temporary success, information, warning, and error notifications. Zap's Flasher supports messages queued in the PHP session as well as messages created in the browser.
Queue a server-side message
Resolve Flasher from the container and call
set(type, title, message). The message is stored in the PHP session,
which makes it useful before redirecting after a successful or failed action.
use Zap\Core\Utils\Flasher;
app(Flasher::class)->set(
'success',
'Profile saved',
'Your changes have been saved.'
);
return $this->redirect(route('profile.edit'));
The supported types are success, info,
warning, and error. Use one of these fixed values so the
matching icon and CSS style are applied.
Render queued messages
The shared layouts/app.blade.php layout calls
Flasher::flash() automatically near the start of the page body. On the
next request, queued messages are rendered and removed from the session queue.
Pages using that layout need no additional template call.
The framework registers the Flasher CSS and JavaScript as default assets in
config/css.php and config/js.php. They load automatically;
do not add another copy to the layout or register an extra script tag.
Show a message in JavaScript
The default flasher JavaScript asset exposes
Flasher.show(type, title, message). It creates the notification
container if necessary, escapes title and message text, and dismisses notifications
automatically after a short delay. Users can also close a notification themselves.
document.addEventListener('DOMContentLoaded', function () {
Flasher.show(
'info',
'Changes pending',
'Your draft has not been submitted yet.'
);
});
Messages already rendered by PHP are also picked up by the JavaScript asset for timed dismissal. The asset works with the shared markup and styles.
Keep notification content safe
- Use the supported fixed message types; do not build a type from request data.
- Pass plain text for titles and messages; the PHP and JavaScript renderers escape these values.
- Keep notification text brief and do not include passwords, tokens, or other secrets.
- Show a generic message to users and record sensitive diagnostic details in server-side logs.
Continue with the Hasher utility guide.