%PDF- %PDF-
Direktori : /var/www/html/camillo/camillo-api-master/app/Http/Resources/ |
Current File : //var/www/html/camillo/camillo-api-master/app/Http/Resources/MinorResource.php |
<?php namespace App\Http\Resources; use App\Models\Classroom; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\Resource; use Illuminate\Support\Facades\Log; class MinorResource extends Resource { protected $classroom; public function setClassroom($value){ $this->classroom = $value ? : $this->resource->getExpectedClassroom(); return $this; } public function __construct($resource) { parent::__construct($resource); } /** * Transform the resource into an array. * * @param \Illuminate\Http\Request $request * @return array */ public function toArray($request) { $status = $this->resource->status($this->classroom); $data = [ "id" => $this->id, "name" => $this->name, "surname" => $this->surname, "birth_date" => $this->birth_date->format("d-m-Y"), "minor" => $this->gender, "fiscal_code" => $this->fiscal_code, "hometown" => $this->hometown, "province" => $this->province, "citizenship" => $this->citizenship, "residence_city" => $this->residence_city, "street" => $this->street, "street_number" => $this->street_number, "zip_code" => $this->zip_code, "pathologies" => $this->pathologies, "intolerance" => $this->intolerance, "notes" => $this->notes, "arrival_time" => $this->classroom ? Carbon::parse($this->classrooms()->where('classroom_id', $this->classroom->id)->first()->pivot->arrival_time)->format("H:i") : null, "arrival_time_today" => Carbon::parse($this->resource->dynamicArrivalTime($this->classroom))->format("H:i"), "current_time" => date("H:i",time()), "is_subscribed" => $this->isSubscribed(), "isFamilyAdmin" => $this->currentUserIsFamilyAdmin(), "classroom" => $this->classroom, "family" => IndividualResource::collection($this->individuals), "status" => $status["status"], "status_description" => $status["description"], "status_color" => $status["color"], "status_weight" => $status["weight"] ]; if(in_array($data["status_description"], ["minor_in_class", "qr_left", "qr_arrived", "minor_left_class"])){ $data["status_time"] = $status["time"]; } return $data; } }