%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Http/Resources/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Http/Resources/ClientResource.php

<?php

namespace App\Http\Resources;

use Carbon\Carbon;
use App\Http\Resources\BookingResource;
use App\Http\Resources\TherapistResource;
use Illuminate\Http\Resources\Json\JsonResource;

class ClientResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $nextSession = $this->bookings()->orderBy('start_date', 'asc')
            ->where('start_date', '>=', Carbon::now())
            ->where('therapist_id', $this->pivot->therapist_id)
            ->notCancelled()
            ->first();

        return [
            'id' => $this->id,
            'therapist' => new TherapistResource($this->pivot->therapist),
            'is_new' => $this->pivot->created_at > Carbon::now()->subDays(7) ? true : false,
            'photo_url' => $this->photo_url ? $this->photo : asset('images/user-placeholder.png'),
            'full_name' => $this->full_name,
            'first_name' => $this->first_name,
            'last_name' => $this->last_name,
            'email' => $this->email,
            'phone' => $this->phone,
            'bookings' => BookingResource::collection($this->bookings->where('therapist_id', $this->pivot->therapist_id)),
            'next_booking' => new BookingResource($nextSession)
        ];
    }
}

Zerion Mini Shell 1.0