adrema/app/Form/Resources/ParticipantResource.php

45 lines
1.1 KiB
PHP
Raw Normal View History

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-03-14 23:54:41 +01:00
return $this->getModel()->getFields()->present();
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 [
'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-02-08 21:04:00 +01:00
];
}
}