Files
portal/app/Http/Resources/TransportResource.php
T
2021-09-02 22:20:01 +08:00

31 lines
1.1 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use Illuminate\Http\Resources\Json\JsonResource;
class TransportResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'type' => $this->type,
'courier' => $this->courier,
'tracking_number' => $this->tracking_number,
'dispatch_date' => $this->dispatch_date ? $this->dispatch_date->format('d-m-Y') : $this->dispatch_date,
'drop_date' => $this->drop_date ? $this->drop_date->format('d-m-Y') : $this->drop_date,
'status' => $this->status,
'current_schedule' => new ScheduleResource($this->schedules()->where('status', '=', ApprovalStatus::APPROVED)->first()),
'schedule_history' => ScheduleResource::collection($this->schedules()->where('status', '=', ApprovalStatus::EXPIRED)->get())
];
}
}