更新用户模型
parent
5366041db6
commit
14f2139e92
|
|
@ -8,6 +8,7 @@ use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class User extends Model implements AuthorizableContract, AuthenticatableContract
|
||||
{
|
||||
|
|
@ -52,4 +53,32 @@ class User extends Model implements AuthorizableContract, AuthenticatableContrac
|
|||
'last_login_at' => 'datetime',
|
||||
'status' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 设置此用户的密码
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setPasswordAttribute($value): void
|
||||
{
|
||||
if ((string) $value === '') {
|
||||
$value = null;
|
||||
} elseif (Hash::needsRehash($value)) {
|
||||
$value = Hash::make($value);
|
||||
}
|
||||
|
||||
$this->attributes['password'] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认给定的密码是否正确
|
||||
*
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyPassword(string $password): bool
|
||||
{
|
||||
return $this->password && Hash::check($password, $this->password);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue