UserItem.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. # app/MicroApi/Services/ResponseHandler.php
  3. namespace App\MicroApi\Items;
  4. use Illuminate\Contracts\Auth\Authenticatable;
  5. use Illuminate\Auth\Passwords\CanResetPassword;
  6. use Illuminate\Notifications\RoutesNotifications;
  7. use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
  8. class UserItem implements Authenticatable, CanResetPasswordContract
  9. {
  10. use RoutesNotifications, CanResetPassword;
  11. public $remember_token;
  12. public $id;
  13. public $name;
  14. public $email;
  15. public $password;
  16. public $status;
  17. protected $hidden = ['password'];
  18. /**
  19. * 将 JSON 序列化对象数据填充到 UserItem
  20. */
  21. public function fillAttributes($data)
  22. {
  23. if (is_object($data)) {
  24. $data = get_object_vars($data);
  25. }
  26. foreach ($data as $key => $value) {
  27. if (in_array($key, $this->hidden)) {
  28. continue;
  29. }
  30. $key = strtolower($key);
  31. switch ($key) {
  32. case 'id':
  33. $this->id = $value;
  34. break;
  35. case 'name':
  36. $this->name = $value;
  37. break;
  38. case 'email':
  39. $this->email = $value;
  40. break;
  41. case 'status':
  42. $this->status = $value;
  43. break;
  44. default:
  45. break;
  46. }
  47. }
  48. return $this;
  49. }
  50. /**
  51. * Get the name of the unique identifier for the user.
  52. *
  53. * @return string
  54. */
  55. public function getAuthIdentifierName()
  56. {
  57. return 'id';
  58. }
  59. /**
  60. * Get the unique identifier for the user.
  61. *
  62. * @return mixed
  63. */
  64. public function getAuthIdentifier()
  65. {
  66. return $this->id;
  67. }
  68. /**
  69. * Get the password for the user.
  70. *
  71. * @return string
  72. */
  73. public function getAuthPassword()
  74. {
  75. return $this->password;
  76. }
  77. /**
  78. * Get the token value for the "remember me" session.
  79. *
  80. * @return string
  81. */
  82. public function getRememberToken()
  83. {
  84. return $this->remember_token;
  85. }
  86. /**
  87. * Set the token value for the "remember me" session.
  88. *
  89. * @param string $value
  90. * @return void
  91. */
  92. public function setRememberToken($value)
  93. {
  94. $this->remember_token = $value;
  95. }
  96. /**
  97. * Get the column name for the "remember me" token.
  98. *
  99. * @return string
  100. */
  101. public function getRememberTokenName()
  102. {
  103. return 'remember_token';
  104. }
  105. }