public function save($newRevision = false, $publishRevision = true)
    {
        if ($newRevision) {
            $revision = new Revision;
            $revision->language_id = $this->revision->language_id;

            $this->revision = $revision;
        }

        DB::transaction(
            function () use ($newRevision, $publishRevision) {
                $this->saveContent();

                $this->saveRevision($publishRevision);

                // Prepare and save fields
                foreach (array_keys($this->data) as $fieldName) {
                    /** @var FieldCollection $field */
                    $field = $this->data[$fieldName];

                    if (!$newRevision) {
                        $field->deleted()->each(function (Field $value) {
                            $value->delete();
                        });
                    }

                    $field->each(function (Field $value, $key) use ($newRevision, $fieldName) {
                        $value->weight = $key;
                        $value->name = $fieldName;
                        $this->saveField($value, $newRevision);
                    });

                    $field->syncOriginal();
                }
            }
        );
    }
public function save($newRevision = false, $publishRevision = true)
    {
        if ($newRevision) {
            $revision = new Revision;
            $revision->language_id = $this->revision->language_id;

            $this->revision = $revision;
        }

        DB::transaction(
            function () use ($newRevision, $publishRevision) {
                $this->saveContent();

                $this->saveRevision($publishRevision);

                // Prepare and save fields
                foreach (array_keys($this->data) as $fieldName) {
                    /** @var FieldCollection $field */
                    $field = $this->data[$fieldName];

                    if (!$newRevision) {
                        $field->deleted()->each(function (Field $value) {
                            $value->delete();
                        });
                    }

                    $field->each(function (Field $value, $key) use ($newRevision, $fieldName) {
                        $value->weight = $key;
                        $value->name = $fieldName;
                        $this->saveField($value, $newRevision);
                    });

                    $field->syncOriginal();
                }
            }
        );
    }
public function save ( $ newRevision = false , $ publishRevision = true ) { if ( $ newRevision ) { $ revision = new Revision ; $ revision -> language_id = $ this -> revision -> language_id ; $ this -> revision = $ revision ; } DB :: transaction ( function ( ) use ( $ newRevision , $ publishRevision ) { $ this -> saveContent ( ) ; $ this -> saveRevision ( $ publishRevision ) ; // Prepare and save fields foreach ( array_keys ( $ this -> data ) as $ fieldName ) { /** @var FieldCollection $field */ $ field = $ this -> data [ $ fieldName ] ; if ( ! $ newRevision ) { $ field -> deleted ( ) -> each ( function ( Field $ value ) { $ value -> delete ( ) ; } ) ; } $ field -> each ( function ( Field $ value , $ key ) use ( $ newRevision , $ fieldName ) { $ value -> weight = $ key ; $ value -> name = $ fieldName ; $ this -> saveField ( $ value , $ newRevision ) ; } ) ; $ field -> syncOriginal ( ) ; } } ) ; }
Save a revision

@param bool $newRevision Should we create a new revision, false by default
@param bool $publishRevision Should we immediately publish this revision, true by default
Save a revision