2024-03-07 00:58:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Transformers;
|
|
|
|
|
|
|
|
use App\Form\Fields\Field;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use Spatie\LaravelData\Support\DataProperty;
|
2024-09-21 22:46:38 +02:00
|
|
|
use Spatie\LaravelData\Support\Transformation\TransformationContext;
|
2024-03-07 00:58:14 +01:00
|
|
|
use Spatie\LaravelData\Transformers\Transformer;
|
|
|
|
|
|
|
|
class FieldCollectionTransformer implements Transformer
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Collection<int, Field> $value
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
2024-09-21 22:46:38 +02:00
|
|
|
public function transform(DataProperty $property, mixed $value, TransformationContext $context): mixed
|
2024-03-07 00:58:14 +01:00
|
|
|
{
|
|
|
|
return $value->map(fn ($field) => [
|
|
|
|
...$field->toArray(),
|
|
|
|
'type' => class_basename($field),
|
|
|
|
])->toArray();
|
|
|
|
}
|
|
|
|
}
|