User.php 951 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Auth\GenericUser;
  4. use Tymon\JWTAuth\Contracts\JWTSubject;
  5. /**
  6. * 授权用户
  7. */
  8. class User extends GenericUser implements JWTSubject,\ArrayAccess
  9. {
  10. public function getJWTIdentifier()
  11. {
  12. $name = $this->getAuthIdentifierName();
  13. return $this->attributes[$name];
  14. }
  15. /**
  16. * token的附加属性
  17. * @return array
  18. */
  19. public function getJWTCustomClaims()
  20. {
  21. return [
  22. 'api_token'=>$this->attributes['api_token']
  23. ];
  24. }
  25. public function offsetExists($offset)
  26. {
  27. return isset($this->attributes[$offset]);
  28. }
  29. public function offsetGet($offset)
  30. {
  31. return $this->attributes[$offset];
  32. }
  33. public function offsetSet($offset, $value)
  34. {
  35. return $this->attributes[$offset] = $value;
  36. }
  37. public function offsetUnset($offset)
  38. {
  39. unset($this->attributes[$offset]);
  40. }
  41. }