protected function persist_do_save( Collection $values ) {

		$added = array();

		foreach ( $values as $value ) {

			$new = ! $this->saver->get_pk( $value );

			// prevent recursion by excluding the relation that references this from being saved.
			$saved = $this->saver->save( $value, array( 'exclude_relations' => $this->other_attribute ) );
			$pk    = $this->saver->get_pk( $saved );

			if ( $new && $pk ) {
				$added[ $pk ] = $saved;

				$values->removeElement( $value );
			}

			$values->dont_remember( function ( Collection $collection ) use ( $saved, $pk ) {
				if ( ! $collection->contains( $saved ) ) {
					$collection->add( $saved );
				}
			} );
		}

		return $added;
	}
protected function persist_do_save( Collection $values ) {

		$added = array();

		foreach ( $values as $value ) {

			$new = ! $this->saver->get_pk( $value );

			// prevent recursion by excluding the relation that references this from being saved.
			$saved = $this->saver->save( $value, array( 'exclude_relations' => $this->other_attribute ) );
			$pk    = $this->saver->get_pk( $saved );

			if ( $new && $pk ) {
				$added[ $pk ] = $saved;

				$values->removeElement( $value );
			}

			$values->dont_remember( function ( Collection $collection ) use ( $saved, $pk ) {
				if ( ! $collection->contains( $saved ) ) {
					$collection->add( $saved );
				}
			} );
		}

		return $added;
	}
protected function persist_do_save ( Collection $ values ) { $ added = array ( ) ; foreach ( $ values as $ value ) { $ new = ! $ this -> saver -> get_pk ( $ value ) ; // prevent recursion by excluding the relation that references this from being saved. $ saved = $ this -> saver -> save ( $ value , array ( 'exclude_relations' => $ this -> other_attribute ) ) ; $ pk = $ this -> saver -> get_pk ( $ saved ) ; if ( $ new && $ pk ) { $ added [ $ pk ] = $ saved ; $ values -> removeElement ( $ value ) ; } $ values -> dont_remember ( function ( Collection $ collection ) use ( $ saved , $ pk ) { if ( ! $ collection -> contains ( $ saved ) ) { $ collection -> add ( $ saved ) ; } } ) ; } return $ added ; }
Save all models that are being persisted.

@since 2.0

@param Collection $values

@return array Models that have been newly created, not updated.
Save all models that are being persisted .