ProviderClientBlockResource.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. use Illuminate\Support\Facades\Storage;
  6. class ProviderClientBlockResource extends JsonResource
  7. {
  8. public function toArray(Request $request): array
  9. {
  10. return [
  11. 'id' => $this->id,
  12. 'provider_id' => $this->provider_id,
  13. 'client_id' => $this->client_id,
  14. 'client_name' => $this->client->user->name ?? null,
  15. 'client_email' => $this->client->user->email ?? null,
  16. 'client_phone' => $this->client->user->phone ?? null,
  17. 'client_rating' => $this->client->average_rating ?? null,
  18. 'client_photo' => $this->resolveClientPhoto(),
  19. 'created_at' => $this->created_at?->format('Y-m-d H:i'),
  20. 'updated_at' => $this->updated_at?->format('Y-m-d H:i'),
  21. ];
  22. }
  23. private function resolveClientPhoto(): ?string
  24. {
  25. $path = $this->client->profileMedia->path ?? null;
  26. return $path ? Storage::temporaryUrl($path, now()->addMinutes(60)) : null;
  27. }
  28. }