Laravel错误:响应内容必须是实现__toString()的字符串或对象,“”;布尔值“;鉴于


Laravel Error: The Response content must be a string or object implementing __toString(), "boolean" given

我在下面的代码中收到了上述错误,完全无法找出真正的原因。

        if ($validation->fails()) {
            // if it fails...
            return Redirect::to("login")->withErrors($validation)->withInput();
        } else {
            // storing user session... if it passes...
            $username =  Input::get("username");
            Session::put("username", $username);
            return Redirect::to("/");
        }

检查filters.php,确保thar闭包通过验证时返回null或不返回。

看起来您正在对用户进行身份验证。为什么不使用开箱即用的Laravel认证呢?

对于您的代码来说,不确定是否是链接的withInput()导致了错误,无论如何,我强烈反对链接withErrors和withInput,因为这会有问题。更好的方法是使用

Input::flash();

请参阅文档