src/Metabox/Manager.php
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;
    }
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;
    }
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 ; }
Handle metabox post meta save.

@param MetaboxInterface $metabox
@param Request          $request

@throws MetaboxException

@return MetaboxInterface
Handle metabox post meta save .