Laravel 5会话不适用于重定向

时间:2018-12-19 12:42:35

标签: php laravel session laravel-5 laravel-session

我在开发Laravel应用程序时遇到麻烦。当我通过函数设置会话并加载视图时,会话将显示:

for student in root:
        students[student.tag] = {}

        for value in student:
            students[student.tag][value.tag] = value.text

但是,当我设置一个会话并将其重定向到该页面中的URL时,该会话将无法工作。我目前正在使用以下代码:

Session::flash("test","ABC");

return view('layout.customer');

3 个答案:

答案 0 :(得分:2)

仅刷新了最后一个请求的变量。

发送重定向时,重定向本身就是发送给访问者的第一个请求。根据此请求,将清除现有的Flash会话。
现在,第二个请求针对要重定向到的页面启动,并且会话闪烁不再存在。


更新

您可以使用with函数将刷新的数据添加到重定向中。

return redirect()->route('customer.details')->with("test","ABC");

更多信息:https://laravel.com/docs/5.7/redirects#redirecting-with-flashed-session-data

答案 1 :(得分:0)

重定向时,您可以使用return redirect()->route('customer.details')->with("test","ABC");刷新数据。这是此文档:https://laravel.com/docs/5.7/redirects#redirecting-with-flashed-session-data

答案 2 :(得分:0)

在customer.details控制器中添加行使用Session;在页面顶部。

相关问题