Files
2026-07-14 17:03:38 +07:00

35 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources\Api\Ticket;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TicketResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'uuid' => $this->uuid,
'ticket_num' => $this->ticket_num,
'subject' => $this->subject,
'description' => $this->description,
'status' => $this->status,
'room' => $this->room,
'data' => $this->data ? (is_string($this->data) ? json_decode($this->data, true) : $this->data) : null,
'gallery' => $this->gallery ?? [],
'customer_id' => $this->customer_id,
'customer' => $this->whenLoaded('customer', fn() => [
'id' => $this->customer->id,
'uuid' => $this->customer->uuid,
'fullname' => $this->customer->fullname,
'email' => $this->customer->email,
]),
'replies' => TicketReplyResource::collection($this->whenLoaded('reply')),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}