50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\Application;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* @mixin Application
|
|
*/
|
|
class ApplicationResource extends JsonResource
|
|
{
|
|
/**
|
|
* `ip_hash` stays out: it exists to spot the same sender twice, not to be
|
|
* handed around.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'kind' => $this->kind->value,
|
|
'status' => $this->status->value,
|
|
'call_id' => $this->call_id,
|
|
'subject' => $this->resource->subject(),
|
|
'name' => $this->name,
|
|
'email' => $this->email,
|
|
'organisation' => $this->organisation,
|
|
'message' => $this->message,
|
|
'hours_per_week' => $this->hours_per_week,
|
|
'links' => (object) ($this->links ?? []),
|
|
'locale' => $this->locale,
|
|
'notes' => $this->notes,
|
|
'handled_by' => $this->whenLoaded('handler', fn () => $this->handler ? [
|
|
'id' => $this->handler->id,
|
|
'name' => $this->handler->name,
|
|
] : null),
|
|
'handled_at' => $this->handled_at?->toIso8601String(),
|
|
|
|
'created_at' => $this->created_at?->toIso8601String(),
|
|
'updated_at' => $this->updated_at?->toIso8601String(),
|
|
'deleted_at' => $this->deleted_at?->toIso8601String(),
|
|
];
|
|
}
|
|
}
|