Home > Software engineering >  Not getting the message from controller to view in laravel
Not getting the message from controller to view in laravel

Time:08-10

i am trying to show a message in the view from controller

in my controller:

if(json_decode($store) === "Error Code 4G5J3F"){
                return redirect()->back()->with('message', 'Error!');
            }

in my view:

@if(session()->has('message'))
<div >
    {{ session()->get('message') }}
</div>
@endif

and it will return back but won't show the message. why is that happening?

CodePudding user response:

I think you need to change from session()->has('message') into Session::has('message)

@if(Session::has('message'))
<div >
    {{ Session::get('message') }}
</div>
@endif

Hopefully this will help

CodePudding user response:

try this

return Redirect::back()->with('message', 'Error!');

CodePudding user response:

There is nothing wrong with your code with flashing message to the session and reading it in the view.

You could double-check if the (json_decode($store) === "Error Code 4G5J3F") condition returns true.

  • Related