belongsTo(User::class); } /** Выпускает (или перевыпускает) токен пользователя; возвращает открытый токен — показать один раз. */ public static function issue(User $user): string { $token = 'hado_agent_'.bin2hex(random_bytes(32)); static::updateOrCreate(['user_id' => $user->id], ['token_hash' => hash('sha256', $token)]); return $token; } public static function findByToken(string $token): ?self { return static::where('token_hash', hash('sha256', $token))->first(); } }