Language

How To Pass a message to another page in Laravel 5.4

Date 13 May, 2017

Details :

1. Just add this code before your redirect code:

return Redirect::to('users/register')->with('message', 'Registered successfully');

2. For Example

 public function deleteposts()
   { 
       $userdata = DB::table('posts')->where('id', 1)->delete();

       return Redirect::to('posts/list')->with('message', 'post deleted successfully');                 
   }

3. and just paste this code in your view (blade file)

  @if(Session::has('message'))
  <p class="alert alert-success">
  	   {!! Session::get('message') !!}
  	   <a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
  	</p>
  @foreach($errors->all() as $error)
      <p>{!! $error !!}</p>
  @endforeach
@endif