LMongo\Eloquent\Model::belongsToMany PHP Method

belongsToMany() public method

Define a many-to-many relationship.
public belongsToMany ( string $related, string $foreignKey = null, string $otherKey = null ) : BelongsToMany
$related string
$foreignKey string
$otherKey string
return LMongo\Eloquent\Relations\BelongsToMany
    public function belongsToMany($related, $foreignKey = null, $otherKey = null)
    {
        // First, we'll need to determine the foreign key and "other key" for the
        // relationship. Once we have determined the keys we'll make the query
        // instances as well as the relationship instances we need for this.
        $foreignKey = $foreignKey ?: $this->getForeignKey();
        $instance = new $related();
        $otherKey = $otherKey ?: $instance->getForeignKey();
        // Now we're ready to create a new query builder for the related model and
        // the relationship instances for the relation. The relations will set
        // appropriate query constraint and entirely manages the hydrations.
        $query = $instance->newQuery();
        return new BelongsToMany($query, $this, $foreignKey, $otherKey);
    }
Model