40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class TicketFieldValueResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'ticket_field_definition_id' => $this->ticket_field_definition_id,
|
|
'ticket_field_definition' => $this->whenLoaded(
|
|
'ticketFieldDefinition',
|
|
fn (): ?array => $this->ticketFieldDefinition === null
|
|
? null
|
|
: TicketFieldDefinitionResource::make($this->ticketFieldDefinition)->resolve(),
|
|
),
|
|
'ticket_id' => $this->ticket_id,
|
|
'user_value' => $this->whenLoaded(
|
|
'userValue',
|
|
fn (): ?array => $this->userValue === null
|
|
? null
|
|
: UserResource::make($this->userValue)->resolve(),
|
|
),
|
|
'value_number' => $this->value_number,
|
|
'value_user_id' => $this->value_user_id,
|
|
'created_at' => $this->created_at?->toISOString(),
|
|
'updated_at' => $this->updated_at?->toISOString(),
|
|
];
|
|
}
|
|
}
|