我正在使用拉拉维尔5.8
和"laracasts/flash": "^3.0"
在我的应用程序中,除了这段非常具体的代码外,所有重定向和闪存消息都运行良好。
/* Controller */
public function show( Test $test) {
$test->checkPermission();
...
}
/* Model */
public function checkPermission()
{
flash()->warning('You can not have access to this.');
return redirect( route('home' ) )->send(); //Notice the send()
}
如果我将此代码与->send()
一起使用(我以前从未使用过),我会很好地重定向到主页,但没有闪存消息。
如果我删除->send()
,我收到了闪光消息,但没有重定向。
我还尝试删除flash()
并使用redirect()->with()
.然后会话包含消息,我被重定向。但我想使用flash()
或至少理解为什么它不适用于这个特定的用例。
控制器应返回重定向,而不是检查权限。尝试返回控制器中返回的检查权限。
尝试在路由上添加 Web 中间件。 或者确保 Web 中间件组包含 StartSession 中间件。
通过 https://laracasts.com/discuss/channels/laravel/auth-session-killed-after-redirect-laravel-52/replies/124991