public function saveFields(MetaboxInterface $metabox, Request $request): MetaboxInterface
    {
        $post_id = $request->query('post_id');
        $data = $this->getMetaboxData(collect($request->get('fields')));
        $fields = $metabox->repository()->all();

        /** @var $validator Validator */
        $validator = $this->factory->make(
            $data,
            $this->getMetaboxRules($fields),
            $this->getMetaboxMessages($fields),
            $this->getMetaboxPlaceholders($fields)
        );

        $validatedData = $validator->valid();

        foreach ($fields as $field) {
            /** @var FieldTypeInterface|CanHandleMetabox|BaseType $field */
            $field->setErrorMessageBag($validator->errors());

            if (method_exists($field, 'metaboxSave')) {
                $value = isset($validatedData[$field->getName()]) ? $validatedData[$field->getName()] : null;
                $field->metaboxSave($value, $post_id);
            } else {
                throw new MetaboxException(
                    'Unable to save ['.$field->getName().']. The [metaboxSave] method is missing.'
                );
            }
        }

        return $metabox;
    }