【问题标题】:Laravel 5.1 - redirect->intended() returns "The HTTP status code "1" is not valid."Laravel 5.1 - redirect->intended() 返回“HTTP 状态码“1”无效。”
【发布时间】:2015-10-09 15:35:21
【问题描述】:

我正在尝试在我的登录功能中实现redirect()->intended() 方法以将现在登录的用户带回他来自的地方,但我总是收到此错误:

Response.php 第 470 行中的 InvalidArgumentException:HTTP 状态 代码“1”无效。`

public function processLogin($region, $lang)
{
  if (Auth::attempt(['email' => $_POST['email'], 'password' => $_POST['password'], 'active' => 1])) {
        return redirect()->intended('index', array('region' => 'ca', 'lang' => 'fr')); // line that messes up
    }
  return redirect()->route('login', array('region' => 'ca', 'lang' => 'fr'))->withErrors('invalid login');
}

当我将intended(...) 更改为route(...) 时,它工作正常,但它总是重定向到索引路由。

我错过了什么吗?

感谢您的帮助!

【问题讨论】:

  • 请记住,intended() 仅在您来自 GET 请求时才有效
  • 我也是这么想的。我确保在GET 路由上填写了登录下拉表单,但这也不起作用。但是现在你提到它,processLogin 函数是一个POST 请求......这会改变什么吗?

标签: php authentication laravel-5.1


【解决方案1】:

试试这个。重定向HTTP code 1 不允许您同时使用另一个参数。重定向意味着您正在发送请求以显示该特定页面在查看和重定向之间存在差异。

我希望这会有所帮助... :)

if (Auth::attempt(['email' => $_POST['email'], 'password' => $_POST['password'], 'active' => 1])) {
    return redirect('index');
}

【讨论】:

    最近更新 更多