*/ class CodeCast implements CastsAttributes { /** @param array $attributes */ public function get(Model $model, string $key, mixed $value, array $attributes): Code { if ($value === null || ! is_string($value)) { throw new \UnexpectedValueException('Code must be a string.'); } return new Code($value); } /** @param array $attributes */ public function set(Model $model, string $key, mixed $value, array $attributes): string { if (! $value instanceof Code) { throw new \UnexpectedValueException('The given value is not an instance of Code.'); } return $value->value; } }