我正在尝试使用此
验证登录时的使用情况 //Attempt to auth the user
if(! auth()->attempt(request(['email','password' => Hash::make(request('password'))])))
{
//If not redirect back
return back()->withErrors([
'message' => 'Please check your email or password'
]);
}
但是我收到了这个错误..
Connection.php第647行中的QueryException: SQLSTATE [42S22]:未找到列:1054未知列&$; $ 2y $ 10 $ 5ysCvqUiloxmtRo2comd9uaiaNkLJ0eiW6x5pDFGWESAbXr5jm5N6'在' where子句' (SQL:select * from
users
其中$2y$10$5ysCvqUiloxmtRo2comd9uaiaNkLJ0eiW6x5pDFGWESAbXr5jm5N6
为空限制1)
请有人帮助我。 谢谢:))
答案 0 :(得分:2)
发生此错误是因为您滥用request()
辅助方法。
如果你愿意,你做了:
request(['email','password' => Hash::make(request('password'))])
它将产生这个数组:
['email' => 'myemail@lol.com', 's9audh87h2ueahjdbas' => null]
request()
方法需要一个数组,其值表示请求中提供的输入的名称。因此,如果你给它一个关联数组,它将完全忽略键,它只会获取它的值。
因此,要获取请求的输入并在授权尝试中使用它,您必须这样做:
$userInput = request('email', 'password');
if (! auth()->attempt($userInput))
{
//do something.
}
假设您的user
表格中有email
和password
列,这是正确的。
答案 1 :(得分:0)
试试这个:
//Attempt to auth the user
if(! auth()->attempt([
'email' => request()->get('email'),
'password' => request()->get('password')
])
{
//If not redirect back
return back()->withErrors([
'message' => 'Please check your email or password'
]);
}
a)您不需要哈希密码,Laravel已经这样做了
b)我不确定你作为参数传递了什么。某种类型的混合数组