public static function add($password, $user = null)
    {
        if (static::isUsed($password, $user) && !$user->allowUsedPassword) {
            throw new InvalidParamException('Password existed.');
        }
        if (static::judgePasswordHash($password)) {
            $passwordHistory = $user->create(static::class);
            $passwordHistory->{$passwordHistory->passwordHashAttribute} = $password;
        } else {
            $passwordHistory = $user->create(static::class, ['password' => $password]);
        }
        /* @var $passwordHistory static */
        return $passwordHistory->save();
    }
public static function add($password, $user = null)
    {
        if (static::isUsed($password, $user) && !$user->allowUsedPassword) {
            throw new InvalidParamException('Password existed.');
        }
        if (static::judgePasswordHash($password)) {
            $passwordHistory = $user->create(static::class);
            $passwordHistory->{$passwordHistory->passwordHashAttribute} = $password;
        } else {
            $passwordHistory = $user->create(static::class, ['password' => $password]);
        }
        /* @var $passwordHistory static */
        return $passwordHistory->save();
    }
public static function add ( $ password , $ user = null ) { if ( static :: isUsed ( $ password , $ user ) && ! $ user -> allowUsedPassword ) { throw new InvalidParamException ( 'Password existed.' ) ; } if ( static :: judgePasswordHash ( $ password ) ) { $ passwordHistory = $ user -> create ( static :: class ) ; $ passwordHistory -> { $ passwordHistory -> passwordHashAttribute } = $ password ; } else { $ passwordHistory = $ user -> create ( static :: class , [ 'password' => $ password ] ) ; } /* @var $passwordHistory static */ return $ passwordHistory -> save ( ) ; }
Add password to history.

@param string $password Password or Password Hash.
@param User $user
@return boolean
@throws InvalidParamException throw if password existed.
Add password to history .