AdminReport.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Services\AccountService;
  4. use App\Services\StatusService;
  5. use App\Story;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Http\Resources\Json\JsonResource;
  8. class AdminReport extends JsonResource
  9. {
  10. /**
  11. * Transform the resource into an array.
  12. *
  13. * @return array<string, mixed>
  14. */
  15. public function toArray(Request $request): array
  16. {
  17. $res = [
  18. 'id' => $this->id,
  19. 'reporter' => AccountService::get($this->profile_id, true),
  20. 'type' => $this->type,
  21. 'object_id' => (string) $this->object_id,
  22. 'object_type' => $this->object_type,
  23. 'reported' => AccountService::get($this->reported_profile_id, true),
  24. 'status' => null,
  25. 'reporter_message' => $this->message,
  26. 'admin_seen_at' => $this->admin_seen,
  27. 'created_at' => $this->created_at,
  28. ];
  29. if ($this->object_id && $this->object_type === 'App\Status') {
  30. $res['status'] = StatusService::get($this->object_id, false);
  31. }
  32. if ($this->object_id && $this->object_type === 'App\Story') {
  33. $story = Story::find($this->object_id);
  34. if ($story) {
  35. $res['story'] = $story->toAdminEntity();
  36. }
  37. }
  38. return $res;
  39. }
  40. }