Redirecting back with a message in Laravel

When you need to redirect to a page but you want to show a message you can use withError in the controller code.

return Redirect::back()->withErrors(['msg', 'The Message']);

Then call error message in your view.

@if($errors->any())

<h4>{{$errors->first()}}</h4>

@endif

To check if the message is there use Session::has(‘msg’)

Session::has('msg')

You can use flash instead.

Session::flash('message', "Special message goes here");

return Redirect::back();

Then call it in the view like this:

@if (Session::has('message'))

   <div class="alert alert-info">{{ Session::get('message') }}</div>

@endif