Laravel 快速消息和重定向无法正常工作
Laravel flash message and redirection not working properly
我正在使用 laravel 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()
。然后会话包含消息 and 我被重定向了。但我想使用 flash()
或至少理解为什么它不适用于这个特定的用例。
尝试在您的路由中添加网络中间件。或者确保 web 中间件组包含 StartSession 中间件。
控制器应该return重定向,而不是检查权限。尝试 return 在控制器中 return 检查权限。
我正在使用 laravel 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()
。然后会话包含消息 and 我被重定向了。但我想使用 flash()
或至少理解为什么它不适用于这个特定的用例。
尝试在您的路由中添加网络中间件。或者确保 web 中间件组包含 StartSession 中间件。
控制器应该return重定向,而不是检查权限。尝试 return 在控制器中 return 检查权限。