@@ -29,7 +29,7 @@ trait HybridRelations
2929 public  function  hasOne ($ related$ foreignKeynull , $ localKeynull )
3030 {
3131 // Check if it is a relation with an original model. 
32-  if  (! is_subclass_of ($ related\ Jenssegers \ Mongodb \ Eloquent \ Model::class)) {
32+  if  (! is_subclass_of ($ related
3333 return  parent ::hasOne ($ related$ foreignKey$ localKey
3434 }
3535
@@ -55,7 +55,7 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
5555 public  function  morphOne ($ related$ name$ typenull , $ idnull , $ localKeynull )
5656 {
5757 // Check if it is a relation with an original model. 
58-  if  (! is_subclass_of ($ related\ Jenssegers \ Mongodb \ Eloquent \ Model::class)) {
58+  if  (! is_subclass_of ($ related
5959 return  parent ::morphOne ($ related$ name$ type$ id$ localKey
6060 }
6161
@@ -79,7 +79,7 @@ public function morphOne($related, $name, $type = null, $id = null, $localKey =
7979 public  function  hasMany ($ related$ foreignKeynull , $ localKeynull )
8080 {
8181 // Check if it is a relation with an original model. 
82-  if  (! is_subclass_of ($ related\ Jenssegers \ Mongodb \ Eloquent \ Model::class)) {
82+  if  (! is_subclass_of ($ related
8383 return  parent ::hasMany ($ related$ foreignKey$ localKey
8484 }
8585
@@ -105,7 +105,7 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
105105 public  function  morphMany ($ related$ name$ typenull , $ idnull , $ localKeynull )
106106 {
107107 // Check if it is a relation with an original model. 
108-  if  (! is_subclass_of ($ related\ Jenssegers \ Mongodb \ Eloquent \ Model::class)) {
108+  if  (! is_subclass_of ($ related
109109 return  parent ::morphMany ($ related$ name$ type$ id$ localKey
110110 }
111111
@@ -142,7 +142,7 @@ public function belongsTo($related, $foreignKey = null, $otherKey = null, $relat
142142 }
143143
144144 // Check if it is a relation with an original model. 
145-  if  (! is_subclass_of ($ related\ Jenssegers \ Mongodb \ Eloquent \ Model::class)) {
145+  if  (! is_subclass_of ($ related
146146 return  parent ::belongsTo ($ related$ foreignKey$ otherKey$ relation
147147 }
148148
@@ -211,13 +211,13 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
211211 /** 
212212 * Define a many-to-many relationship. 
213213 * 
214-  * @param string $related 
215-  * @param string $collection 
216-  * @param string $foreignKey 
217-  * @param string $otherKey 
218-  * @param string $parentKey 
219-  * @param string $relatedKey 
220-  * @param string $relation 
214+  * @param class- string<\Illuminate\Database\Eloquent\Model>  $related 
215+  * @param string|null  $collection 
216+  * @param string|null  $foreignKey 
217+  * @param string|null  $otherKey 
218+  * @param string|null  $parentKey 
219+  * @param string|null  $relatedKey 
220+  * @param string|null  $relation 
221221 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany 
222222 */ 
223223 public  function  belongsToMany (
@@ -237,7 +237,7 @@ public function belongsToMany(
237237 }
238238
239239 // Check if it is a relation with an original model. 
240-  if  (! is_subclass_of ($ related\ Jenssegers \ Mongodb \ Eloquent \ Model::class)) {
240+  if  (! is_subclass_of ($ related
241241 return  parent ::belongsToMany (
242242 $ related
243243 $ collection
@@ -249,13 +249,18 @@ public function belongsToMany(
249249 );
250250 }
251251
252+ 252253 // First, we'll need to determine the foreign key and "other key" for the 
253254 // relationship. Once we have determined the keys we'll make the query 
254255 // instances as well as the relationship instances we need for this. 
255256 $ foreignKey$ foreignKey$ this getForeignKey ().'s ' ;
256257
257258 $ instancenew  $ related
258259
260+  if  ($ otherKey$ relation
261+  throw  new  \LogicException (sprintf ('In %s::%s(), the key cannot be identical to the relation name "%s". The default key is "%s". ' , static ::class, $ relation$ relation$ instancegetForeignKey ().'s ' ));
262+  }
263+ 259264 $ otherKey$ otherKey$ instancegetForeignKey ().'s ' ;
260265
261266 // If no table name was provided, we can guess it by concatenating the two 
@@ -301,7 +306,7 @@ protected function guessBelongsToManyRelation()
301306 */ 
302307 public  function  newEloquentBuilder ($ query
303308 {
304-  if  (is_subclass_of ($ this \ Jenssegers \ Mongodb \ Eloquent \ Model::class)) {
309+  if  (is_subclass_of ($ this 
305310 return  new  Builder ($ query
306311 }
307312
0 commit comments