0

I want to access -value I tried $token->value, $token->getValue() I'm not sure how to access this please someone help me

$token=Tymon\JWTAuth\Token {#1960
          -value: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vd29ya3BvcnRhbC5sb2NhbC9hcGkvdjEvYXV0aGVudGljYXRlLXBpbiIsImlhdCI6MTYyMDIwMzQzOSwiZXhwIjoxNjIwNDYyNjM5LCJuYmYiOjE2MjAyMDM0MzksImp0aSI6IkdmOFJjSWRubk13MHdoeEkiLCJzdWIiOjEsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.y8ddEfcV3Gf703onpu2YmX0n7FcHUq78JEW6eOr9Rhs"
        }
Michael Rovinsky
  • 6,807
  • 7
  • 15
  • 30
Ruzaik Nazeer
  • 474
  • 2
  • 12
  • 2
    Does this answer your question? [Accessing Class Properties with Spaces](https://stackoverflow.com/questions/7027615/accessing-class-properties-with-spaces) – CBroe May 05 '21 at 08:49
  • Or [Special characters in property name of object](https://stackoverflow.com/questions/10455775/special-characters-in-property-name-of-object) – CBroe May 05 '21 at 08:49
  • 1
    if the attribute is public, you can do it with the dupplicated answer. if you're looking for a declared method, use `get_class_methods($token)` to get a list of available methods on that object. it should be ->payload btw – N69S May 05 '21 at 09:01
  • N69S your solution worked for me since my object value is private I can't use that duplicate answer and your method gave me all the available methods which I can use to access the value thank you very much. – Ruzaik Nazeer May 05 '21 at 09:05
  • The `-` in front of the `value` means it's private, which means the developers of that library don't want you to access that variable. Perhaps looking into the documentation of that library you can find an alternative way to access the data correctly – apokryfos May 05 '21 at 09:36

1 Answers1

0

Try this: $token = auth()->tokenById($userId);

From documentation of library which you use: https://jwt-auth.readthedocs.io/en/develop/auth-guard/

Michael Rovinsky
  • 6,807
  • 7
  • 15
  • 30