Flash Session in laravel and PHP

If you wish to add flash data to a redirect and show the message on the destination page instead, Livewire is smart enough to persist the flash data for one more request. For example:

return redirect('contactform/')->with('message','Your message has been sent!');
@if (session('message'))

  <div class="alert alert-success">
      {{ session('message') }}
  </div>

@endif
In PHP:

session_start();

$_SESSION['flash'] = 'Registered';
session_start();

if (isset($_SESSION['flash'])) {
   echo $_SESSION['flash'];
   unset($_SESSION['flash']);
}

 

Leave a Reply