ClientProviderBlockResource.php 1.2 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Enums\GenderEnum;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class ClientProviderBlockResource extends JsonResource
  7. {
  8. public function toArray(Request $request): array
  9. {
  10. $gender = $this->gender ?? $this->provider?->gender?->value;
  11. return [
  12. 'id' => $this->id,
  13. 'client_id' => $this->client_id,
  14. 'provider_id' => $this->provider_id,
  15. 'provider_name' => $this->provider_name ?? $this->provider?->user?->name,
  16. 'gender' => $gender,
  17. 'gender_label' => $gender ? GenderEnum::tryFrom($gender)?->label() : null,
  18. 'provider_email' => $this->provider_email ?? $this->provider?->user?->email,
  19. 'provider_phone' => $this->provider_phone ?? $this->provider?->user?->phone,
  20. 'provider_district' => $this->provider_district ?? null,
  21. 'provider_rating' => $this->provider_rating ?? null,
  22. 'created_at' => $this->created_at?->format('Y-m-d H:i'),
  23. 'updated_at' => $this->updated_at?->format('Y-m-d H:i'),
  24. ];
  25. }
  26. }