更新时间:2023-12-03 22:44:28
您code是窃听,因为您传递了错误的变量验证::尝试()
。该方法需要与钥匙的用户名,密码和可选记住一个数组。有鉴于此,你上面code应该是:
Your code is bugging out because you are passing the wrong variables to Auth::attempt()
. That method requires an array with keys username, password and optionally remember. In that light, your above code should be:
Route::post('login', function()
{
$credentials = [
'username' => Input::get('email'),
'password' => Input::get('password')
];
dd(Auth::attempt($credentials));
});
希望有所帮助。
此外,我会给你额外的code段,以提高您的工作流程。路径来存储新用户:
Also I'll give you snippets of extra code to improve your work flow. Route to store new user:
Route::post('register', function()
{
$input = Input::only(['username', 'email', 'password']);
// validate data
Eloquent::unguard();
$user = User::create($input);
Auth::loginUsingId($user->id);
return Redirect::to('dashboard');
});
然后在你的用户模型中添加方法
Then in your user model add the method
public function setPasswordAttribute()
{
$this->password = Hash::make($this->password);
}
这样的密码会被自动哈希每次它的设置时间
This way the password will be automatically hashed every time it's set