1

I am having trouble with developing a Laravel application. When I set a session from a function and loaded the view the session will show:

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

return view('layout.customer');

But when I set a session and redirect it to a URL in that page, the session will not work. I am currently using following code:

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

return redirect()->route('customer.details');
4

3 回答 3

2

仅在最后一个请求中闪烁的变量。

当您发送重定向时,重定向本身是发送给访问者的第一个请求。在这个请求中,现有的闪存会话被清除。
现在对被重定向到的页面开始第二个请求,并且会话闪烁不再存在。


更新:

您可以使用该with功能将闪存数据添加到重定向。

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

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

于 2018-12-19T12:45:11.923 回答
0

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

于 2018-12-19T12:46:42.747 回答
-1

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

于 2018-12-19T12:49:16.590 回答