【问题标题】:Laravel flash message and redirection not working properlyLaravel Flash 消息和重定向无法正常工作
【发布时间】:2019-12-19 23:28:43
【问题描述】:

我正在使用 laravel 5.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() 或至少了解为什么它不适用于这个特定的用例。

【问题讨论】:

    标签: laravel session redirect laravel-5 laravel-5.8


    【解决方案1】:

    控制器应该返回重定向,而不是检查权限。尝试返回控制器中返回的检查权限。

    【讨论】:

      【解决方案2】:

      尝试在您的路由上添加网络中间件。或确保 web 中间件组包含 StartSession 中间件。

      通过https://laracasts.com/discuss/channels/laravel/auth-session-killed-after-redirect-laravel-52/replies/124991

      【讨论】:

        猜你喜欢
        • 2014-09-30
        • 1970-01-01
        • 2023-01-29
        • 2021-04-11
        • 2017-09-23
        • 2015-08-09
        • 2014-07-01
        • 2015-12-21
        • 2017-03-04
        相关资源
        最近更新 更多