mandant-crm/backend/app/Modules/History/Resources/HistoryEntryResource.php

35 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Modules\History\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class HistoryEntryResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'client_id' => $this->client_id,
'is_field_change' => $this->isFieldChange(),
'history_entry_type_id' => $this->history_entry_type_id,
// Field-change audit rows render under a fixed system label; user
// entries take their configured type name.
'type_name' => $this->isFieldChange() ? 'Stammdatenänderung' : $this->entryType?->name,
'requires_datetime' => $this->entryType?->requires_datetime ?? false,
// Naive local datetime (no Z/offset) so the user-typed HH:MM
// round-trips without timezone drift.
'occurred_at' => $this->occurred_at?->format('Y-m-d\TH:i:s'),
'body' => $this->body,
'custom_field_definition_id' => $this->custom_field_definition_id,
'author_id' => $this->author_id,
'author_name' => $this->author?->name,
'updated_by' => $this->updated_by,
'updated_by_name' => $this->updatedBy?->name,
'created_at' => $this->created_at->toISOString(),
'updated_at' => $this->updated_at->toISOString(),
];
}
}