Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

browntown's avatar

Not seeing newly created session variable in blade template.

I'm using Laravel 5.3.

I want to redirect back to a payment page if a user's credit card has been declined. When a user's card is declined they're redirected back to the payment page with the following:

return redirect()->back()->with('msg', "Your card was declined");

I am able to see this in my Controller.

$msg = (session('msg')) ? session('msg') : "";

I'm passing the $msg variable to my Controller...and trying to display it in the template but...nothing.

I am able to see the "msg" variable in debugbar.

I am NOT able to see the variable in my blade templates. session('msg') Session::get('msg') and every other option I was able to find do not work.

I'm trying to display the message in my template with the following:

@if (session('msg'))
                            <div class="alert alert-danger">
                                {{ session('msg') }}
                            </div>
                        @endif

It's almost like my view needs to be re-rendered in order to display the variable.

Any thoughts?

Thanks!

0 likes
3 replies
browntown's avatar

@sustained not yet. It's still on my bug list...calling for me...whispering my name. Thanks for the help. I'm hoping to get to it today. I'll confirm if that solves my issue.

1 like

Please or to participate in this conversation.