GroupShareResource.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Resources\V3;
  3. use App\Models\Share;
  4. use Illuminate\Http\Request;
  5. /**
  6. * 团队文档里的一项:共享给团队的一个资源。
  7. *
  8. * `role` 由 v2 的 power 换来:10 → reader(只读),20 → editor(可编辑)。
  9. * `resource` 由 Service 按类型批量取好挂上来,**本类不查库**;资源已被删掉时 title / owner_id 为 null。
  10. *
  11. * @mixin Share
  12. */
  13. class GroupShareResource extends BaseResource
  14. {
  15. /**
  16. * @param Request $request
  17. * @return array{
  18. * id: string,
  19. * role: string,
  20. * resource: array{type: string, id: string, title: string|null, owner_id: string|null, owner: array{id: string, nickName: string, userName: string, realName: string, sn: int, avatar: string|null, roles: array|null}|null},
  21. * created_at: string
  22. * }
  23. */
  24. public function toArray($request): array
  25. {
  26. return [
  27. 'id' => (string) $this->id,
  28. 'role' => (int) $this->power >= 20 ? 'editor' : 'reader',
  29. 'resource' => $this->getAttribute('resource'),
  30. 'created_at' => $this->created_at,
  31. ];
  32. }
  33. }