2
0

MeResource.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Services\UserService;
  4. use App\Services\V3\SessionService;
  5. use Illuminate\Http\Request;
  6. /**
  7. * 当前登录用户本人的资料。
  8. *
  9. * 前几个字段与 v3 其他资源里的 user 摘要同形({@see UserService::profile()},
  10. * 驼峰是 v2 留下的既有口径,前端的 IUser 就是这个形状);roles 恒为数组,
  11. * 另加只有本人能看的 email。
  12. *
  13. * 载荷是 {@see SessionService} 拼好的数组。
  14. */
  15. class MeResource extends BaseResource
  16. {
  17. /**
  18. * @param Request $request
  19. * @return array{
  20. * id: string,
  21. * nickName: string,
  22. * userName: string,
  23. * realName: string,
  24. * sn: int,
  25. * avatar: string|null,
  26. * roles: string[],
  27. * email: string
  28. * }
  29. */
  30. public function toArray($request): array
  31. {
  32. return [
  33. 'id' => $this->resource['id'],
  34. 'nickName' => $this->resource['nickName'],
  35. 'userName' => $this->resource['userName'],
  36. 'realName' => $this->resource['realName'],
  37. 'sn' => $this->resource['sn'],
  38. 'avatar' => $this->resource['avatar'],
  39. 'roles' => $this->resource['roles'],
  40. 'email' => $this->resource['email'],
  41. ];
  42. }
  43. }