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;
|
|
|
|
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
|
|
|
* @param array<string, mixed> $context
|
|
|
|
* @return FieldCollection
|
|
|
|
*/
|
|
|
|
public function cast(DataProperty $property, mixed $value, array $context): mixed
|
|
|
|
{
|
|
|
|
return new FieldCollection(collect($value)->map(fn ($value) => Field::classFromType($value['type'])::from($value))->all());
|
|
|
|
}
|
|
|
|
}
|