DirectoryProfile.php 861 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use Cache;
  5. use App\Services\AccountService;
  6. class DirectoryProfile extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @param \Illuminate\Http\Request $request
  12. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  13. */
  14. public function toArray($request)
  15. {
  16. $account = AccountService::get($this->id, true);
  17. if(!$account) {
  18. return [];
  19. }
  20. $url = url($this->username);
  21. return [
  22. 'id' => $this->id,
  23. 'name' => $this->name,
  24. 'username' => $this->username,
  25. 'url' => $url,
  26. 'avatar' => $account['avatar'],
  27. 'following_count' => $account['following_count'],
  28. 'followers_count' => $account['followers_count'],
  29. 'statuses_count' => $account['statuses_count'],
  30. 'bio' => $account['note_text']
  31. ];
  32. }
  33. }