*/ class OrderEmployeeCast implements CastsAttributes { /** @param array $attributes */ public function get(Model $model, string $key, mixed $value, array $attributes): ?OrderEmployee { if (is_null($value)) { return null; } if (! is_string($value)) { throw new InvalidArgumentException('The value must be a string.'); } $data = Arr::wrap(json_decode($value, true)); return new OrderEmployee( matricule: new Matricule(Arr::string($data, 'matricule')), firstname: Arr::string($data, 'firstname'), lastname: Arr::string($data, 'lastname'), facility: Arr::string($data, 'facility'), site: Arr::string($data, 'site'), service: Arr::string($data, 'service'), ); } /** @param array $attributes */ public function set(Model $model, string $key, mixed $value, array $attributes): ?string { if ($value === null) { return null; } if (! $value instanceof OrderEmployee) { throw new InvalidArgumentException('The given value is not an instance of OrderEmployee.'); } return json_encode([ 'matricule' => $value->matricule->value, 'firstname' => $value->firstname, 'lastname' => $value->lastname, 'facility' => $value->facility, 'site' => $value->site, 'service' => $value->service, ], JSON_THROW_ON_ERROR); } }