src/mako/database/midgard/relations/ManyToMany.php
public function synchronize(array $ids): bool
	{
		$success = true;

		$keys = $this->getJunctionKeys($ids);

		// Fetch existing links

		$existing = $this->junction()->where($this->getForeignKey(), '=', $this->parent->getPrimaryKeyValue())->select([$this->getJunctionKey()])->all()->pluck($this->getJunctionKey());

		// Link new relations

		if(!empty($diff = array_diff($keys, $existing)))
		{
			$success = $success && $this->link($diff);
		}

		// Unlink old relations

		if(!empty($diff = array_diff($existing, $keys)))
		{
			$success = $success && $this->unlink($diff);
		}

		// Return status

		return $success;
	}
public function synchronize(array $ids): bool
	{
		$success = true;

		$keys = $this->getJunctionKeys($ids);

		// Fetch existing links

		$existing = $this->junction()->where($this->getForeignKey(), '=', $this->parent->getPrimaryKeyValue())->select([$this->getJunctionKey()])->all()->pluck($this->getJunctionKey());

		// Link new relations

		if(!empty($diff = array_diff($keys, $existing)))
		{
			$success = $success && $this->link($diff);
		}

		// Unlink old relations

		if(!empty($diff = array_diff($existing, $keys)))
		{
			$success = $success && $this->unlink($diff);
		}

		// Return status

		return $success;
	}
public function synchronize ( array $ ids ) : bool { $ success = true ; $ keys = $ this -> getJunctionKeys ( $ ids ) ; // Fetch existing links $ existing = $ this -> junction ( ) -> where ( $ this -> getForeignKey ( ) , '=' , $ this -> parent -> getPrimaryKeyValue ( ) ) -> select ( [ $ this -> getJunctionKey ( ) ] ) -> all ( ) -> pluck ( $ this -> getJunctionKey ( ) ) ; // Link new relations if ( ! empty ( $ diff = array_diff ( $ keys , $ existing ) ) ) { $ success = $ success && $ this -> link ( $ diff ) ; } // Unlink old relations if ( ! empty ( $ diff = array_diff ( $ existing , $ keys ) ) ) { $ success = $ success && $ this -> unlink ( $ diff ) ; } // Return status return $ success ; }
Synchronize related records.

@param  array $ids An array of ids and/or models
@return bool
Synchronize related records .