AdminModeratedProfileResource.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Resources\Admin;
  3. use App\Profile;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class AdminModeratedProfileResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @return array<string, mixed>
  12. */
  13. public function toArray(Request $request): array
  14. {
  15. $profileObj = [];
  16. $profile = Profile::withTrashed()->find($this->profile_id);
  17. if ($profile) {
  18. $profileObj = [
  19. 'name' => $profile->name,
  20. 'username' => $profile->username,
  21. 'username_str' => explode('@', $profile->username)[1],
  22. 'remote_url' => $profile->remote_url,
  23. ];
  24. }
  25. return [
  26. 'id' => $this->id,
  27. 'domain' => $this->domain,
  28. 'profile' => $profileObj,
  29. 'profile_id' => $this->profile_id,
  30. 'profile_url' => $this->profile_url,
  31. 'note' => $this->note,
  32. 'is_banned' => (bool) $this->is_banned,
  33. 'is_nsfw' => (bool) $this->is_nsfw,
  34. 'is_unlisted' => (bool) $this->is_unlisted,
  35. 'is_noautolink' => (bool) $this->is_noautolink,
  36. 'is_nodms' => (bool) $this->is_nodms,
  37. 'is_notrending' => (bool) $this->is_notrending,
  38. 'created_at' => now()->parse($this->created_at)->format('c'),
  39. ];
  40. }
  41. }