@@ -225,7 +225,7 @@ public static function boot() {
225
225
if (method_exists ($ myself , $ method )) {
226
226
$ eventMethod = $ rad .$ event ;
227
227
self ::$ eventMethod (function ($ model ) use ($ method ){
228
- return $ model ->$ method ();
228
+ return $ model ->$ method ($ model );
229
229
});
230
230
}
231
231
}
@@ -353,9 +353,10 @@ public function __call($method, $parameters) {
353
353
*
354
354
* @param string $related
355
355
* @param string $foreignKey
356
+ * @param string $otherKey
356
357
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
357
358
*/
358
- public function belongsTo ($ related , $ foreignKey = null ) {
359
+ public function belongsTo ($ related , $ foreignKey = NULL , $ otherKey = NULL , $ relation = NULL ) {
359
360
$ backtrace = debug_backtrace (false );
360
361
$ caller = ($ backtrace [1 ]['function ' ] == 'handleRelationalArray ' )? $ backtrace [3 ] : $ backtrace [1 ];
361
362
@@ -372,10 +373,12 @@ public function belongsTo($related, $foreignKey = null) {
372
373
// for the related models and returns the relationship instance which will
373
374
// actually be responsible for retrieving and hydrating every relations.
374
375
$ instance = new $ related ;
375
-
376
+
377
+ $ otherKey = $ otherKey ?: $ instance ->getKeyName ();
378
+
376
379
$ query = $ instance ->newQuery ();
377
380
378
- return new BelongsTo ($ query , $ this , $ foreignKey , $ relation );
381
+ return new BelongsTo ($ query , $ this , $ foreignKey , $ otherKey , $ relation );
379
382
}
380
383
381
384
/**
0 commit comments