How to show session flash message in laravel 8

How to set session flash message and display in laravel 8


In this article, you will be learning about how to set or show flash message in laravel 8, where flash message works with the help of session.

So, Lets see few example about it:


Example 1: 

Paste below code in controller:

use Illuminate\Support\Facades\Session;

Session::flash('message','This is a flash message!');

Paste below code in blade file:

@if(Session::has('message'))
    <h5 class="alert alert-success">{{Session::get('message') }}</h5>
@endif


Example 2:

Paste below code in controller:

use Illuminate\Support\Facades\Session;

Session::flash('flash_message', 'This is a flash message');
Session::flash('flash_type', 'alert-success');

Paste below code in blade file:

@if( Session::has('flash_message') )
  <div class="alert {{ Session::get('flash_type') }}">
      <h5>{{ Session::get('flash_message') }}</h5>
  </div>
@endif



Thanks for reading.