$value) { if (property_exists($this, $key)) { $this->$key = $value; } else { $this->attributes[$key] = $value; } } } /** * Get user identifier (email or username) */ public function getIdentifier(): string { return $this->email ?: $this->username; } /** * Get user ID */ public function getId(): int|string { return $this->id; } /** * Get custom attribute */ public function getAttribute(string $key): mixed { return $this->attributes[$key] ?? null; } /** * Set custom attribute */ public function setAttribute(string $key, mixed $value): void { $this->attributes[$key] = $value; } /** * Convert to array */ public function toArray(): array { return [ 'id' => $this->id, 'username' => $this->username, 'email' => $this->email, 'created_at' => $this->createdAt, 'updated_at' => $this->updatedAt, ] + $this->attributes; } /** * Convert to safe array (without sensitive data) */ public function toSafeArray(): array { $data = $this->toArray(); unset($data['password'], $data['remember_token']); return $data; } }