| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Http\Resources;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class CustomScheduleResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'schedule_id' => $this->schedule_id,
- 'address_type' => $this->address_type,
- 'service_type_id' => $this->service_type_id,
- 'service_type_name' => $this->whenLoaded('serviceType', function () {
- return $this->serviceType->description;
- }),
- 'description' => $this->description,
- 'min_price' => number_format($this->min_price, 2, '.', ''),
- 'max_price' => number_format($this->max_price, 2, '.', ''),
- 'offers_meal' => $this->offers_meal,
- 'created_at' => $this->created_at?->format('Y-m-d H:i'),
- 'updated_at' => $this->updated_at?->format('Y-m-d H:i'),
-
- 'schedule' => $this->whenLoaded('schedule', function () {
- return [
- 'id' => $this->schedule->id,
- 'client_id' => $this->schedule->client_id,
- 'provider_id' => $this->schedule->provider_id,
- 'client_name' => $this->schedule->client?->user?->name,
- 'address_id' => $this->schedule->address_id,
- 'address' => $this->schedule->address ? [
- 'street' => $this->schedule->address->street,
- 'number' => $this->schedule->address->number,
- 'complement' => $this->schedule->address->complement,
- 'neighborhood' => $this->schedule->address->neighborhood,
- 'city' => $this->schedule->address->city,
- 'state' => $this->schedule->address->state,
- 'zipcode' => $this->schedule->address->zipcode,
- ] : null,
- 'date' => $this->schedule->date?->format('d/m/Y'),
- 'period_type' => $this->schedule->period_type,
- 'start_time' => $this->schedule->start_time,
- 'end_time' => $this->schedule->end_time,
- 'status' => $this->schedule->status,
- ];
- }),
-
- 'specialities' => $this->whenLoaded('specialities', function () {
- return $this->specialities->map(function ($item) {
- return [
- 'id' => $item->id,
- 'name' => $item->description,
- ];
- });
- }),
- ];
- }
- }
|