2024-03-07 00:58:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Form\Casts;
|
|
|
|
|
|
|
|
use App\Form\Data\FieldCollection;
|
|
|
|
use App\Form\Fields\Field;
|
|
|
|
use Spatie\LaravelData\Casts\Cast;
|
2024-09-21 22:46:38 +02:00
|
|
|
use Spatie\LaravelData\Support\Creation\CreationContext;
|
2024-03-07 00:58:14 +01:00
|
|
|
use Spatie\LaravelData\Support\DataProperty;
|
|
|
|
|
|
|
|
class FieldCollectionCast implements Cast
|
|
|
|
{
|
|
|
|
/**
|
2024-06-29 11:18:40 +02:00
|
|
|
* @param array<int, array<string, string>> $value
|
2024-03-07 00:58:14 +01:00
|
|
|
* @return FieldCollection
|
|
|
|
*/
|
2024-09-21 22:46:38 +02:00
|
|
|
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): mixed
|
2024-03-07 00:58:14 +01:00
|
|
|
{
|
|
|
|
return new FieldCollection(collect($value)->map(fn ($value) => Field::classFromType($value['type'])::from($value))->all());
|
|
|
|
}
|
|
|
|
}
|