laravel - Laravel Flash 消息和重定向无法正常工作
问题描述
我正在使用 laravel5.8
和"laracasts/flash": "^3.0"
在我的应用程序中,除了这段非常具体的代码之外,所有重定向和 Flash 消息都运行良好。
/* 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 消息,但我没有被重定向。
我还尝试删除flash()
和使用redirect()->with()
. 然后会话包含消息,我被重定向。但我想使用flash()
或至少了解为什么它不适用于这个特定的用例。
解决方案
控制器应该返回重定向,而不是检查权限。尝试返回控制器中返回的检查权限。
推荐阅读
- nfc - 锁定的 NFC 标签仍然可以格式化吗?
- php - 根据多个类别为 WooCommerce 订单号添加前缀
- python - 有没有办法在数据框中的两个字符串列之间执行编辑距离?
- javascript - Vue Js 3:使用 Prop 默认值作为模板字符串
- php - 如何从 laravel 雄辩的关系中对急切加载进行分组
- css - 将css添加到父div中特定类的最后一个子元素的选择器之后
- asp.net-core - 在 ASP.NET Core 中组合默认和命名的 CORS 策略
- javascript - 为什么地址变量在这里不取cliptext的值。?
- javascript - 将质子原生的记事本示例从js转换为tsx的问题
- python - Groupby 包含两个特定的值 - pandas