src/Milky/Database/Eloquent/Relations/BelongsToMany.php
protected function attachNew(array $records, array $current, $touch = true)
	{
		$changes = ['attached' => [], 'updated' => []];

		foreach ($records as $id => $attributes) {
			// If the ID is not in the list of existing pivot IDs, we will insert a new pivot
			// record, otherwise, we will just update this existing record on this joining
			// table, so that the developers will easily update these records pain free.
			if (! in_array($id, $current)) {
				$this->attach($id, $attributes, $touch);

				$changes['attached'][] = is_numeric($id) ? (int) $id : (string) $id;
			}

			// Now we'll try to update an existing pivot record with the attributes that were
			// given to the method. If the model is actually updated we will add it to the
			// list of updated pivot records so we return them back out to the consumer.
			elseif (count($attributes) > 0 &&
				$this->updateExistingPivot($id, $attributes, $touch)) {
				$changes['updated'][] = is_numeric($id) ? (int) $id : (string) $id;
			}
		}

		return $changes;
	}
protected function attachNew(array $records, array $current, $touch = true)
	{
		$changes = ['attached' => [], 'updated' => []];

		foreach ($records as $id => $attributes) {
			// If the ID is not in the list of existing pivot IDs, we will insert a new pivot
			// record, otherwise, we will just update this existing record on this joining
			// table, so that the developers will easily update these records pain free.
			if (! in_array($id, $current)) {
				$this->attach($id, $attributes, $touch);

				$changes['attached'][] = is_numeric($id) ? (int) $id : (string) $id;
			}

			// Now we'll try to update an existing pivot record with the attributes that were
			// given to the method. If the model is actually updated we will add it to the
			// list of updated pivot records so we return them back out to the consumer.
			elseif (count($attributes) > 0 &&
				$this->updateExistingPivot($id, $attributes, $touch)) {
				$changes['updated'][] = is_numeric($id) ? (int) $id : (string) $id;
			}
		}

		return $changes;
	}
protected function attachNew ( array $ records , array $ current , $ touch = true ) { $ changes = [ 'attached' => [ ] , 'updated' => [ ] ] ; foreach ( $ records as $ id => $ attributes ) { // If the ID is not in the list of existing pivot IDs, we will insert a new pivot // record, otherwise, we will just update this existing record on this joining // table, so that the developers will easily update these records pain free. if ( ! in_array ( $ id , $ current ) ) { $ this -> attach ( $ id , $ attributes , $ touch ) ; $ changes [ 'attached' ] [ ] = is_numeric ( $ id ) ? ( int ) $ id : ( string ) $ id ; } // Now we'll try to update an existing pivot record with the attributes that were // given to the method. If the model is actually updated we will add it to the // list of updated pivot records so we return them back out to the consumer. elseif ( count ( $ attributes ) > 0 && $ this -> updateExistingPivot ( $ id , $ attributes , $ touch ) ) { $ changes [ 'updated' ] [ ] = is_numeric ( $ id ) ? ( int ) $ id : ( string ) $ id ; } } return $ changes ; }
Attach all of the IDs that aren't in the current array.

@param  array  $records
@param  array  $current
@param  bool   $touch
@return array
Attach all of the IDs that aren t in the current array .