2
0

UserResource.php 941 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Models\UserInfo;
  4. use Illuminate\Http\Request;
  5. /**
  6. * 账号本人能看到的账号信息(`user_infos` 表)。
  7. *
  8. * id 是 `userid`(uuid),不是自增主键——与 v2 的用户对象口径一致。
  9. * 只列白名单字段:密码哈希、各种 token 不出这个类。
  10. *
  11. * @mixin UserInfo
  12. */
  13. class UserResource extends BaseResource
  14. {
  15. /**
  16. * @param Request $request
  17. * @return array{
  18. * id: string,
  19. * username: string,
  20. * nickname: string,
  21. * email: string,
  22. * created_at: string|null
  23. * }
  24. */
  25. public function toArray($request): array
  26. {
  27. return [
  28. 'id' => $this->userid,
  29. 'username' => $this->username,
  30. 'nickname' => $this->nickname,
  31. 'email' => $this->email,
  32. 'created_at' => $this->created_at?->toIso8601ZuluString(),
  33. ];
  34. }
  35. }