Skip to content

Commit 066e219

Browse files
authored
fix for Laravel 5.5
fix HybridRelations::belongsToMany not compatible with Model::belongsToMany. This is incompatible with 5.4
1 parent c4a5264 commit 066e219

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/Jenssegers/Mongodb/Eloquent/HybridRelations.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,20 @@ public function morphTo($name = null, $type = null, $id = null)
204204
}
205205
}
206206

207-
/**
207+
**
208208
* Define a many-to-many relationship.
209209
*
210210
* @param string $related
211211
* @param string $collection
212-
* @param string $foreignKey
213-
* @param string $otherKey
212+
* @param string $foreignPivotKey
213+
* @param string $relatedPivotKey
214+
* @param string $parentKey
215+
* @param string $relatedKey
214216
* @param string $relation
215217
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
216218
*/
217-
public function belongsToMany($related, $collection = null, $foreignKey = null, $otherKey = null, $relation = null)
219+
public function belongsToMany($related, $collection = null, $foreignPivotKey = null, $relatedPivotKey = null,
220+
$parentKey = null, $relatedKey = null, $relation = null)
218221
{
219222
// If no relationship name was passed, we will pull backtraces to get the
220223
// name of the calling function. We will use that function name as the
@@ -225,17 +228,18 @@ public function belongsToMany($related, $collection = null, $foreignKey = null,
225228

226229
// Check if it is a relation with an original model.
227230
if (! is_subclass_of($related, \Jenssegers\Mongodb\Eloquent\Model::class)) {
228-
return parent::belongsToMany($related, $collection, $foreignKey, $otherKey, $relation);
231+
return parent::belongsToMany($related, $collection = null, $foreignPivotKey = null, $relatedPivotKey = null,
232+
$parentKey = null, $relatedKey = null, $relation = null);
229233
}
230234

231235
// First, we'll need to determine the foreign key and "other key" for the
232236
// relationship. Once we have determined the keys we'll make the query
233237
// instances as well as the relationship instances we need for this.
234-
$foreignKey = $foreignKey ?: $this->getForeignKey().'s';
238+
$foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey().'s';
235239

236240
$instance = new $related;
237241

238-
$otherKey = $otherKey ?: $instance->getForeignKey().'s';
242+
$relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey().'s';
239243

240244
// If no table name was provided, we can guess it by concatenating the two
241245
// models using underscores in alphabetical order. The two model names
@@ -249,7 +253,9 @@ public function belongsToMany($related, $collection = null, $foreignKey = null,
249253
// appropriate query constraint and entirely manages the hydrations.
250254
$query = $instance->newQuery();
251255

252-
return new BelongsToMany($query, $this, $collection, $foreignKey, $otherKey, $relation);
256+
return new BelongsToMany($query, $this, $collection,
257+
$foreignPivotKey, $relatedPivotKey,
258+
$parentKey, $relatedKey, $relation);
253259
}
254260

255261
/**

0 commit comments

Comments
 (0)