MeGroupResource.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Http\Resources\Concerns\ResolvesActor;
  4. use App\Models\GroupMember;
  5. use Illuminate\Http\Request;
  6. /**
  7. * 我加入的一个团队,带我在里面的角色。载荷是成员记录,团队信息来自预加载的 group。
  8. *
  9. * `id` 是团队的 uid:调用方拿它当团队空间的身份、调 `/v3/groups/{group}/members`。
  10. * 我自己那条成员记录的 id 在 `member_id`,退出团队时用。
  11. *
  12. * @mixin GroupMember
  13. */
  14. class MeGroupResource extends BaseResource
  15. {
  16. use ResolvesActor;
  17. /**
  18. * @param Request $request
  19. * @return array{
  20. * id: string,
  21. * name: string,
  22. * description: string|null,
  23. * owner_id: string,
  24. * owner: array{id: string, nickName: string, userName: string, realName: string, sn: int, avatar: string|null, roles: array|null}|null,
  25. * status: int,
  26. * role: string,
  27. * member_id: string,
  28. * created_at: string,
  29. * joined_at: string
  30. * }
  31. */
  32. public function toArray($request): array
  33. {
  34. return [
  35. 'id' => $this->group_id,
  36. 'name' => $this->group->name,
  37. 'description' => $this->group->description,
  38. 'owner_id' => $this->group->owner,
  39. 'owner' => $this->actor($this->group->creator),
  40. 'status' => (int) $this->group->status,
  41. 'role' => $this->effectiveRole(),
  42. 'member_id' => (string) $this->id,
  43. 'created_at' => $this->group->created_at,
  44. 'joined_at' => $this->created_at,
  45. ];
  46. }
  47. }