*/ use HasFactory, Notifiable; /** * The attributes that are mass assignable. * * @var list */ protected $fillable = [ 'name', 'email_hash', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'email_hash', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', ]; } /** * Hash an email address using HMAC-SHA256. */ public static function hashEmail(string $email): string { return hash_hmac('sha256', strtolower(trim($email)), config('app.key')); } /** * Find a user by their email address. */ public static function findByEmail(string $email): ?self { $emailHash = self::hashEmail($email); return self::where('email_hash', $emailHash)->first(); } /** * Get the magic login tokens for the user. */ public function magicLoginTokens(): HasMany { return $this->hasMany(MagicLoginToken::class, 'email_hash', 'email_hash'); } }