Laravel Redirect Back with() Message

Mudit Tuli picture Mudit Tuli · Nov 7, 2013 · Viewed 451.5k times · Source

I am trying to redirect to the previous page with a message when there is a fatal error.

App::fatal(function($exception)
{
    return Redirect::back()->with('msg', 'The Message');
}

In the view trying to access the msg with

Sessions::get('msg')

But nothing is getting rendered, am I doing something wrong here?

Answer

giannis christofakis picture giannis christofakis · Nov 7, 2013

Try

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

and inside your view call this

@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif