@@ -225,7 +225,7 @@ public static function boot() {
225225 if (method_exists ($ myself , $ method )) {
226226 $ eventMethod = $ rad .$ event ;
227227 self ::$ eventMethod (function ($ model ) use ($ method ){
228- return $ model ->$ method ();
228+ return $ model ->$ method ($ model );
229229 });
230230 }
231231 }
@@ -353,9 +353,10 @@ public function __call($method, $parameters) {
353353 *
354354 * @param string $related
355355 * @param string $foreignKey
356+ * @param string $otherKey
356357 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
357358 */
358- public function belongsTo ($ related , $ foreignKey = null ) {
359+ public function belongsTo (( $ related , $ foreignKey = NULL , $ otherKey = NULL , $ relation = NULL ) {
359360 $ backtrace = debug_backtrace (false );
360361 $ caller = ($ backtrace [1 ]['function ' ] == 'handleRelationalArray ' )? $ backtrace [3 ] : $ backtrace [1 ];
361362
@@ -372,10 +373,12 @@ public function belongsTo($related, $foreignKey = null) {
372373 // for the related models and returns the relationship instance which will
373374 // actually be responsible for retrieving and hydrating every relations.
374375 $ instance = new $ related ;
375-
376+
377+ $ otherKey = $ otherKey ?: $ instance ->getKeyName ();
378+
376379 $ query = $ instance ->newQuery ();
377380
378- return new BelongsTo ($ query , $ this , $ foreignKey , $ relation );
381+ return new BelongsTo ($ query , $ this , $ foreignKey , $ otherKey , $ relation );
379382 }
380383
381384 /**
0 commit comments