2023-12-31 22:35:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Resources;
|
|
|
|
|
2024-01-01 18:29:33 +01:00
|
|
|
use App\Form\Fields\Field;
|
2023-12-31 22:35:13 +01:00
|
|
|
use App\Form\Models\Form;
|
2024-01-01 16:53:32 +01:00
|
|
|
use App\Form\Models\Formtemplate;
|
2024-01-01 18:29:33 +01:00
|
|
|
use App\Group;
|
2024-01-01 16:53:32 +01:00
|
|
|
use App\Lib\HasMeta;
|
2023-12-31 22:35:13 +01:00
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @mixin Form
|
|
|
|
*/
|
|
|
|
class FormResource extends JsonResource
|
|
|
|
{
|
2024-01-01 16:53:32 +01:00
|
|
|
|
|
|
|
use HasMeta;
|
|
|
|
|
2023-12-31 22:35:13 +01:00
|
|
|
/**
|
|
|
|
* Transform the resource into an array.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function toArray($request)
|
|
|
|
{
|
|
|
|
return [
|
2024-01-01 18:29:33 +01:00
|
|
|
'id' => $this->id,
|
2023-12-31 22:35:13 +01:00
|
|
|
'name' => $this->name,
|
|
|
|
'from_human' => $this->from?->format('d.m.Y'),
|
|
|
|
'to_human' => $this->to?->format('d.m.Y'),
|
|
|
|
'from' => $this->from?->format('Y-m-d'),
|
|
|
|
'to' => $this->to?->format('Y-m-d'),
|
|
|
|
'excerpt' => $this->excerpt,
|
|
|
|
'description' => $this->description,
|
|
|
|
'mail_top' => $this->mail_top,
|
|
|
|
'mail_bottom' => $this->mail_bottom,
|
|
|
|
'registration_from' => $this->registration_from?->format('Y-m-d H:i:s'),
|
|
|
|
'registration_until' => $this->registration_until?->format('Y-m-d H:i:s'),
|
2024-01-01 16:43:40 +01:00
|
|
|
'config' => $this->config,
|
2024-01-01 18:29:33 +01:00
|
|
|
'links' => [
|
|
|
|
'update' => route('form.update', ['form' => $this->getModel()]),
|
|
|
|
'destroy' => route('form.destroy', ['form' => $this->getModel()]),
|
|
|
|
]
|
2023-12-31 22:35:13 +01:00
|
|
|
];
|
|
|
|
}
|
2024-01-01 16:53:32 +01:00
|
|
|
|
|
|
|
public static function meta(): array
|
|
|
|
{
|
|
|
|
return [
|
2024-01-01 18:29:33 +01:00
|
|
|
'base_url' => url(''),
|
|
|
|
'groups' => Group::forSelect(),
|
|
|
|
'fields' => Field::asMeta(),
|
2024-01-01 16:53:32 +01:00
|
|
|
'links' => [
|
|
|
|
'store' => route('form.store'),
|
2024-01-01 18:29:33 +01:00
|
|
|
'formtemplate_index' => route('formtemplate.index'),
|
2024-01-01 16:53:32 +01:00
|
|
|
],
|
|
|
|
'templates' => FormtemplateResource::collection(Formtemplate::get()),
|
2024-01-01 18:29:33 +01:00
|
|
|
'default' => [
|
|
|
|
'description' => '',
|
|
|
|
'name' => '',
|
|
|
|
'excerpt' => '',
|
|
|
|
'from' => null,
|
|
|
|
'to' => null,
|
|
|
|
'registration_from' => null,
|
|
|
|
'registration_until' => null,
|
|
|
|
'mail_top' => null,
|
|
|
|
'mail_bottom' => null,
|
|
|
|
'config' => null,
|
|
|
|
],
|
|
|
|
'section_default' => [
|
|
|
|
'name' => '',
|
|
|
|
'intro' => '',
|
|
|
|
'fields' => [],
|
|
|
|
]
|
2024-01-01 16:53:32 +01:00
|
|
|
];
|
|
|
|
}
|
2023-12-31 22:35:13 +01:00
|
|
|
}
|