Laravel Flash Message
This package provides a Laravel Flash Message that can be used to display an one-time status message to your users.
return redirect() ->route('login') ->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: $testResponse->assertHasSuccessMessage();
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.
assertHasInfoMessage('Message'): Asserts that a flash message was set using
assertHasSuccessMessage('Message'): Asserts that a flash message was set using
assertHasWarningMessage('Message'): Asserts that a flash message was set using
assertHasErrorMessage('Message'): Asserts that a flash message was set using
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:
- Publish our template into your application by running the following artisan command:
php artisan vendor:publish --provider="Ubient\FlashMessage\FlashMessageServiceProvider"
- Modify the template located at
- 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 firstname.lastname@example.org instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.