ProviderResource.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\Provider;
  4. use Carbon\Carbon;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  7. use Illuminate\Http\Resources\Json\JsonResource;
  8. class ProviderResource extends JsonResource
  9. {
  10. public function toArray(Request $request): array
  11. {
  12. return [
  13. 'id' => $this->id,
  14. 'document' => $this->document,
  15. 'rg' => $this->rg,
  16. 'user_id' => $this->user_id,
  17. 'share_code' => $this->share_code,
  18. 'user' => $this->user,
  19. 'average_rating' => $this->average_rating,
  20. 'total_services' => $this->total_services,
  21. 'birth_date' => $this->birth_date ? Carbon::parse($this->birth_date)->format('d/m/Y') : null,
  22. 'gender' => $this->gender?->value,
  23. 'gender_label' => $this->gender?->label(),
  24. 'selfie_verified' => $this->selfie_verified,
  25. 'document_verified' => $this->document_verified,
  26. 'approval_status' => $this->approval_status?->value ?? $this->approval_status,
  27. 'identity_verification_status' => $this->identity_verification_status?->value,
  28. 'identity_verified_at' => $this->identity_verified_at,
  29. 'identity_verification_attempts' => $this->identity_verification_attempts,
  30. 'identity_verification' => $this->user?->latestIdentityVerification
  31. ? new IdentityVerificationResource($this->user->latestIdentityVerification)
  32. : null,
  33. 'daily_price_8h' => $this->daily_price_8h,
  34. 'daily_price_6h' => $this->daily_price_6h,
  35. 'daily_price_4h' => $this->daily_price_4h,
  36. 'daily_price_2h' => $this->daily_price_2h,
  37. 'profile_media_id' => $this->profileMedia?->id,
  38. 'recipient_id' => $this->recipient_id,
  39. 'recipient_default_bank_account' => $this->recipient_default_bank_account,
  40. 'has_primary_bank_account' => $this->relationLoaded('primaryBankAccount')
  41. ? $this->primaryBankAccount !== null
  42. : $this->primaryBankAccount()->exists(),
  43. 'bank_accounts' => ProviderBankAccountResource::collection($this->whenLoaded('bankAccounts')),
  44. 'profile_media' => $this->profileMedia ? new MediaResource($this->profileMedia) : null,
  45. 'document_front_media' => $this->whenLoaded('documentFrontMedia', fn () => $this->documentFrontMedia ? new MediaResource($this->documentFrontMedia) : null),
  46. 'document_back_media' => $this->whenLoaded('documentBackMedia', fn () => $this->documentBackMedia ? new MediaResource($this->documentBackMedia) : null),
  47. 'created_at' => Carbon::parse($this->created_at)->format('d/m/Y H:i'),
  48. 'updated_at' => Carbon::parse($this->updated_at)->format('d/m/Y H:i'),
  49. ];
  50. }
  51. public static function collection($resource): AnonymousResourceCollection
  52. {
  53. return parent::collection($resource);
  54. }
  55. }