我使用的是laravel 5.0。我想使用auth laravel登录,但我只需要在登录时输入用户名(不需要电子邮件和/或密码)。我已将代码更改为以下代码:
在我的LoginController
:
public function getLogin(){
if(!Auth::check()) {
return view('auth.login');
}
else{
return redirect('home');
}
}
public function postLogin(){
Auth::attempt([
'USER_NAME' => Input::get('username')
]);
return redirect('home');
}
在我的User
模型:
<?php namespace App;
use IlluminateAuthAuthenticatable;
use IlluminateDatabaseEloquentModel;
use IlluminateAuthPasswordsCanResetPassword;
use IlluminateContractsAuthAuthenticatable as AuthenticatableContract;
use IlluminateContractsAuthCanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
protected $table = 'MS_USER_ROLE';
}
我得到了一个错误:
在EloquentUserProvider.php第111行出现ErrorException:未定义索引:password
你知道怎么解决这个吗?
查看Laravel认证的文档
您希望使用Auth::login()
方法显式地登录它们。
public function postLogin()
{
$user = User::where('USER_NAME', '=', Input::get('username'))->firstOrFail();
Auth::login($user);
return redirect('home');
}
如果你是通过用户名认证,只需手动登录:
public function postLogin()
{
$user = User::whereUsername(request('username'))->firstOrFail():
Auth::login($user);
return redirect('home');
}
https://laravel.com/docs/5.2/authentication用户身份验证