protected function duplicatePivotedRelation($relation, $relation_name, $clone) {

		// If duplicating between databases, do not duplicate relations. The related
		// instance may not exist in the other database or could have a different
		// primary key.
		if ($this->write_connection) return;

		// Loop trough current relations and attach to clone
		$relation->get()->each(function ($foreign) use ($clone, $relation_name) {
			$pivot_attributes = array_except($foreign->pivot->getAttributes(), [
				$foreign->pivot->getRelatedKey(),
				$foreign->pivot->getForeignKey(),
				$foreign->pivot->getCreatedAtColumn(),
				$foreign->pivot->getUpdatedAtColumn()
			]);
			$clone->$relation_name()->attach($foreign, $pivot_attributes);
		});
	}
protected function duplicatePivotedRelation($relation, $relation_name, $clone) {

		// If duplicating between databases, do not duplicate relations. The related
		// instance may not exist in the other database or could have a different
		// primary key.
		if ($this->write_connection) return;

		// Loop trough current relations and attach to clone
		$relation->get()->each(function ($foreign) use ($clone, $relation_name) {
			$pivot_attributes = array_except($foreign->pivot->getAttributes(), [
				$foreign->pivot->getRelatedKey(),
				$foreign->pivot->getForeignKey(),
				$foreign->pivot->getCreatedAtColumn(),
				$foreign->pivot->getUpdatedAtColumn()
			]);
			$clone->$relation_name()->attach($foreign, $pivot_attributes);
		});
	}
protected function duplicatePivotedRelation ( $ relation , $ relation_name , $ clone ) { // If duplicating between databases, do not duplicate relations. The related // instance may not exist in the other database or could have a different // primary key. if ( $ this -> write_connection ) return ; // Loop trough current relations and attach to clone $ relation -> get ( ) -> each ( function ( $ foreign ) use ( $ clone , $ relation_name ) { $ pivot_attributes = array_except ( $ foreign -> pivot -> getAttributes ( ) , [ $ foreign -> pivot -> getRelatedKey ( ) , $ foreign -> pivot -> getForeignKey ( ) , $ foreign -> pivot -> getCreatedAtColumn ( ) , $ foreign -> pivot -> getUpdatedAtColumn ( ) ] ) ; $ clone -> $ relation_name ( ) -> attach ( $ foreign , $ pivot_attributes ) ; } ) ; }
Duplicate a many-to-many style relation where we are just attaching the
relation to the dupe

@param  Illuminate\Database\Eloquent\Relations\Relation $relation
@param  string $relation_name
@param  Illuminate\Database\Eloquent\Model $clone
@return void
Duplicate a many - to - many style relation where we are just attaching the relation to the dupe