我想laravel 5.3 loged in users table status =' Active'但状态='无效'无法进入。
请帮助我。非常感谢!
答案 0 :(得分:1)
转到\ vendor \ laravel \ framework \ src \ Illuminate \ Foundation \ Auth \ AuthenticatesUsers.php 然后更改凭证功能。 请参阅此链接https://laracasts.com/discuss/channels/laravel/allowing-only-active-users-to-login。
示例功能链接
受保护的功能凭证(请求$请求) { $ crendentials = $ request-> only($ this-> username(),'password'); $ crendentials [ '状态'] = '有效'; return $ crendentials; }
答案 1 :(得分:1)
在Auth / LoginController.php中添加此功能
use Illuminate\Http\Request;
protected function credentials(Request $request)
{
return [
$this->username() => $request->get($this->username()),
'password' => $request->get('password'),
'active' => 1
];
}
通过这样做,你实际上覆盖它。此函数位于AuthenticatesUsers特征中。
获得相同结果的另一种方法是通过添加
来覆盖validateLogin()函数use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
protected function validateLogin(Request $request)
{
$this->validate($request, [
$this->username() => [
'required',
Rule::exists('users')->where(function ($query) {
$query->where('active', 1);
}),
],
'password' => 'required',
]);
}
到LoginController.php
答案 2 :(得分:0)
您可以尝试这样:
if (Auth::attempt(['email' => $email, 'password' => $password, 'status' => 'Active'])) {
// The user is active, not suspended, and exists.
}