'datetime', 'birthday' => 'date', 'status' => UserStatus::class, ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'email', 'password', 'username', 'first_name', 'last_name', 'phone', 'avatar', 'address', 'country_id', 'birthday', 'last_login', 'confirmation_token', 'status', 'remember_token', 'role_id', 'email_verified_at', ]; /** * The attributes excluded from the model's JSON form. * * @var array */ protected $hidden = ['password', 'remember_token']; /** * Always encrypt password when it is updated. */ public function setPasswordAttribute(string $value): void { $this->attributes['password'] = bcrypt($value); } public function setBirthdayAttribute($value): void { $this->attributes['birthday'] = trim($value) ?: null; } public function gravatar(): string { $hash = hash('md5', strtolower(trim($this->attributes['email']))); return sprintf('https://www.gravatar.com/avatar/%s?size=150', $hash); } public function isUnconfirmed(): bool { return $this->status == UserStatus::UNCONFIRMED; } public function isActive(): bool { return $this->status == UserStatus::ACTIVE; } public function isBanned(): bool { return $this->status == UserStatus::BANNED; } public function country(): BelongsTo { return $this->belongsTo(Country::class, 'country_id'); } public function sendPasswordResetNotification($token): void { Mail::to($this)->send(new \Vanguard\Mail\ResetPassword($token)); event(new RequestedPasswordResetEmail($this)); } public function twoFactorEnabled(): bool { return !!$this->two_factor_confirmed_at && !!$this->two_factor_secret; } public function needsTwoFactorVerification(): bool { return !$this->two_factor_confirmed_at && !!$this->two_factor_secret; } }