Sunday, January 2, 2022

[FIXED] Laravel Redirect Back with() Message

Issue

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?


Solution

Try

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

and inside your view call this

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


Answered By - giannis christofakis

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.