Refactor Inertia responses to use resources
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class TicketWorklogEntryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'actor' => $this->whenLoaded(
|
||||
'actor',
|
||||
fn (): ?array => $this->actor === null
|
||||
? null
|
||||
: UserResource::make($this->actor)->resolve(),
|
||||
),
|
||||
'actor_id' => $this->actor_id,
|
||||
'changes' => $this->changes,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'entry_type' => $this->entry_type?->value,
|
||||
'summary' => $this->summary,
|
||||
'ticket_id' => $this->ticket_id,
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user