Laravel 7 Flash Message example

In this article, I am going to explain the laravel 7 flash message example. This article goes in detailed on flash message in controller laravel 7. I would like to show you how to display flash message in laravel 7 after login or post data in database.

Flash notifications are required in laravel 7 application because that way we can give alter with what progress complete, error, warning etc. In this tutorial, I added several ways to give a flash message like redirect with success message, redirect with an error message, redirect with a warning message and redirect with info message. In this example, we use a bootstrap flash alert layout that way it becomes good layout.

Read Also: Laravel 7 Email Verification

Let’s get started with create flash message laravel 7.

There we will define many types of flash message notification like alert success, alert danger, alert info, alert warning messages in bootstrap laravel 7 projects and display these according to task like on success display success message when gettting any error then dispaly error message etc.

So let’s follow below step:

Step 1: Create Global File For Flash Message

we will create new blade file flash-message.blade.php and write code for messages like success,error,warning,info and validation errors etc.

resources/views/flash-message.blade.php

Read Also: Integrate PayUmoney Payment Gateway

Step 2: Use Flash Message file in app.blade.php file like as bellow:

Step 3: Use Flash Messages with Redirect

In this step I will be show you how to redirect with message like error, success etc.

1. Redirect with success message

We can redirect route or redirect URL or redirect back with success flash message, we can use in controller like this way:

2. Redirect with error message

We can redirect route or redirect URL or redirect back with error flash message, we can use in controller like this way:

Read Also: Log All SQL Queries In Laravel

3. Redirect with warning message

We can simple redirect route or redirect URL or redirect back with warning flash message, we can use in controller like this way:

4. Redirect with info message

We can redirect route or redirect URL or redirect back with info flash message, we can use in controller like this way:

I hope you found your best…

Leave a Comment