AdminUser.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Services\AccountService;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class AdminUser extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @param \Illuminate\Http\Request $request
  11. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  12. */
  13. public function toArray($request)
  14. {
  15. $account = AccountService::get($this->profile_id, true);
  16. $res = [
  17. 'id' => (string) $this->id,
  18. 'profile_id' => (string) $this->profile_id,
  19. 'name' => $this->name,
  20. 'username' => $this->username,
  21. 'is_admin' => (bool) $this->is_admin,
  22. 'email' => $this->email,
  23. 'email_verified_at' => $this->email_verified_at,
  24. 'two_factor_enabled' => (bool) $this->{'2fa_enabled'},
  25. 'register_source' => $this->register_source,
  26. 'app_register_ip' => $this->app_register_ip,
  27. 'has_interstitial' => (bool) $this->has_interstitial,
  28. 'last_active_at' => $this->last_active_at,
  29. 'created_at' => $this->created_at,
  30. ];
  31. if ($account) {
  32. $res['avatar'] = $account['avatar'];
  33. $res['bio'] = $account['note_text'];
  34. $res['statuses_count'] = (int) $account['statuses_count'];
  35. $res['following_count'] = (int) $account['following_count'];
  36. $res['followers_count'] = (int) $account['followers_count'];
  37. $res['is_private'] = (bool) $account['locked'];
  38. }
  39. return $res;
  40. }
  41. }