Laravel Flash数据无限期存在 [英] Laravel Flash Data Persisting indefinitely

查看:112
本文介绍了Laravel Flash数据无限期存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示使用flashdata提交表单的响应,但它会永久存在.

I am showing the response for a form submission using the flashdata, but it is persisting forever.

例如,当表单通过验证并成功提交后,将显示成功消息,并且无论我刷新页面或转到其他页面多少次,它仍会显示成功消息.

For example, when a form is validated and submitted successfully, the success message is shown and no matter how many times I refresh the page or go to other pages, it is still showing the success message.

我的重定向(验证后)如下:

My redirect (after validation) is as follows:

// Redirect back with success message
return redirect()->back()
->with('form_' . $form->identifier . '_response', json_encode([
    'status' => 'success'
]));

在视图中它像这样检查:

And in the view it checks like this:

@if(session('form_'.$form->identifier.'_response'))

        @if(json_decode(session('form_'.$form->identifier.'_response'),true)['status'] == 'success')

            <div class="alert alert-success">Form has been submitted, thank you!</div>

        @endif
@endif

但是它始终显示成功提交div后的所有时间.有人知道在哪里寻找问题吗?谢谢!

But it is showing the success div all the time after first submission. Anyone know where to look for the problem? Thanks!

推荐答案

我发现这与在其中一个控制器中不包含web中间件有关,这是一个愚蠢的错误.

I found out it was about not including web middleware in one of the controllers, silly mistake.

表单处理程序控制器包含web中间件,因此它将设置会话,但是显示表单的控制器没有该中间件,因此不会从会话中删除Flash数据.

The form handler controller had web middleware included, so it would set the session, but the controller displaying the form did not have that middleware, so it would not remove the flash data from the session.

这篇关于Laravel Flash数据无限期存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆