A Laravel package to display flash messages to your users in a fluent, clean, testable and easy-to-use way!
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Laravel Flash Message

Latest Version Build Status Quality Score StyleCI Total Downloads

This package provides a Laravel Flash Message that can be used to display an one-time status message to your users.


When redirecting, you can fluently chain one of the available methods, similar to how you would flash other session data:

return redirect()
    ->withErrorMessage('To execute this action, you need to be logged in first.');

With the message flashed to the session, all that remains is to display it to your users. A good place to start doing so, is by including the alert we've shipped with this package into your view(s):


If you're testing your application, and would like to assert whether the flash message was set, you can do so by calling one of the available assertions on the TestResponse object:

// @see https://laravel.com/docs/5.7/http-tests#testing-json-apis
$testResponse = $this->post('/topics/1/replies', ['message' => 'My example reply']);

// Assert that the success flash message was set, and that it contains the expected message:
$testResponse->assertHasSuccessMessage('Your reply has been added.');

// Alternatively, we can also assert that some (any) success flash message was set:

Available Methods

  • withInfoMessage('Message'): Flashes a message that indicates a neutral informative change or action.
  • withSuccessMessage('Message'): Flashes a message that indicates a successful or positive action.
  • withWarningMessage('Message'): Flashes a message that indicates a warning that might need attention.
  • withErrorMessage('Message'): Flashes a message that indicates an erroneous, dangerous or negative action.

Available Assertions

  • assertHasInfoMessage('Message'): Asserts that a flash message was set using withInfoMessage.
  • assertHasSuccessMessage('Message'): Asserts that a flash message was set using withSuccessMessage
  • assertHasWarningMessage('Message'): Asserts that a flash message was set using withWarningMessage
  • assertHasErrorMessage('Message'): Asserts that a flash message was set using withErrorMessage

Customizing the template

By default, our alert uses TailwindCSS's utility classes to style the alert, but odds are you're either using something else or want to modify how the alert looks altogether. Luckily, doing so is fairly easy:

  1. Publish our template into your application by running the following artisan command:
php artisan vendor:publish --provider="Ubient\FlashMessage\FlashMessageServiceProvider"
  1. Modify the template located at resources/views/vendor/flash-message/alert.blade.php.
  2. That's all! Laravel will automatically pick up on the changes you've made.


You can install the package via composer:

composer require ubient/laravel-flash-message

The package will automatically register itself.


You can run the test using:



Please see UPGRADING for details.


Please see CHANGELOG for more information what has changed recently.


Please see CONTRIBUTING for details.


If you discover any security related issues, please email claudio@ubient.net instead of using the issue tracker.


The MIT License (MIT). Please see License File for more information.