GroupResource.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Http\Resources\Concerns\ResolvesActor;
  4. use App\Models\GroupInfo;
  5. use Illuminate\Http\Request;
  6. /**
  7. * 一个团队。
  8. *
  9. * `role` 是**查看者**在团队里的角色(不是成员就是 null),只在详情、新建、修改时给,
  10. * 搜索列表里没有。`owner` 是创建者的公开摘要。**本类不查库**:creator 来自预加载,
  11. * role 由 Service 挂在 `viewer_role` 上。
  12. *
  13. * @mixin GroupInfo
  14. */
  15. class GroupResource extends BaseResource
  16. {
  17. use ResolvesActor;
  18. /**
  19. * @param Request $request
  20. * @return array{
  21. * id: string,
  22. * name: string,
  23. * description: string|null,
  24. * status: int,
  25. * owner: array{id: string, nickName: string, userName: string, realName: string, sn: int, avatar: string|null, roles: array|null}|null,
  26. * role?: string|null,
  27. * created_at: string,
  28. * updated_at: string
  29. * }
  30. */
  31. public function toArray($request): array
  32. {
  33. return [
  34. 'id' => $this->uid,
  35. 'name' => $this->name,
  36. 'description' => $this->description,
  37. 'status' => (int) $this->status,
  38. 'owner' => $this->actor($this->creator),
  39. 'role' => $this->when(array_key_exists('viewer_role', $this->resource->getAttributes()), fn () => $this->viewer_role),
  40. 'created_at' => $this->created_at,
  41. 'updated_at' => $this->updated_at,
  42. ];
  43. }
  44. }