2024-02-08 21:04:00 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Resources;
|
|
|
|
|
|
|
|
use App\Form\Models\Form;
|
2024-02-09 00:21:33 +01:00
|
|
|
use App\Form\Models\Participant;
|
2024-02-08 21:04:00 +01:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
2024-02-09 00:21:33 +01:00
|
|
|
/**
|
|
|
|
* @mixin Participant
|
|
|
|
*/
|
2024-02-08 21:04:00 +01:00
|
|
|
class ParticipantResource extends JsonResource
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2024-02-09 00:21:33 +01:00
|
|
|
* @return array<string, mixed>
|
2024-02-08 21:04:00 +01:00
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
2024-04-12 00:14:02 +02:00
|
|
|
return [
|
|
|
|
...$this->getModel()->getFields()->present(),
|
|
|
|
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
|
|
|
|
'created_at_display' => $this->created_at->format('d.m.Y'),
|
|
|
|
];
|
2024-02-08 21:04:00 +01:00
|
|
|
}
|
|
|
|
|
2024-02-09 00:21:33 +01:00
|
|
|
/**
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
2024-02-08 21:04:00 +01:00
|
|
|
public static function meta(Form $form): array
|
|
|
|
{
|
|
|
|
return [
|
2024-02-21 23:18:31 +01:00
|
|
|
'form_meta' => $form->meta,
|
|
|
|
'links' => [
|
|
|
|
'update_form_meta' => route('form.update-meta', ['form' => $form]),
|
|
|
|
],
|
2024-02-20 01:04:53 +01:00
|
|
|
'columns' => $form->getFields()
|
|
|
|
->map(fn ($field) => [
|
2024-02-08 23:09:51 +01:00
|
|
|
'name' => $field->name,
|
|
|
|
'base_type' => class_basename($field),
|
|
|
|
'id' => $field->key,
|
2024-03-07 00:58:14 +01:00
|
|
|
'display_attribute' => $field->getDisplayAttribute(),
|
2024-02-20 01:04:53 +01:00
|
|
|
])
|
2024-04-12 00:14:02 +02:00
|
|
|
->push([
|
|
|
|
'name' => 'Registriert am',
|
|
|
|
'id' => 'created_at',
|
|
|
|
'display_attribute' => 'created_at_display'
|
|
|
|
])
|
2024-02-08 21:04:00 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|