@@ -74,7 +74,7 @@ public function __construct(Builder $query, Model $child, $foreignKey, $ownerKey
74
74
*/
75
75
public function getResults ()
76
76
{
77
- if (is_null ($ this ->child ->{ $ this ->foreignKey } )) {
77
+ if (is_null ($ this ->getForeignKeyFrom ( $ this ->child ) )) {
78
78
return $ this ->getDefaultFor ($ this ->parent );
79
79
}
80
80
@@ -94,7 +94,7 @@ public function addConstraints()
94
94
// of the related models matching on the foreign key that's on a parent.
95
95
$ table = $ this ->related ->getTable ();
96
96
97
- $ this ->query ->where ($ table .'. ' .$ this ->ownerKey , '= ' , $ this ->child ->{ $ this ->foreignKey } );
97
+ $ this ->query ->where ($ table .'. ' .$ this ->ownerKey , '= ' , $ this ->getForeignKeyFrom ( $ this ->child ) );
98
98
}
99
99
}
100
100
@@ -130,7 +130,7 @@ protected function getEagerModelKeys(array $models)
130
130
// to query for via the eager loading query. We will add them to an array then
131
131
// execute a "where in" statement to gather up all of those related records.
132
132
foreach ($ models as $ model ) {
133
- if (! is_null ($ value = $ model ->{ $ this ->foreignKey } )) {
133
+ if (! is_null ($ value = $ this ->getForeignKeyFrom ( $ model ) )) {
134
134
$ keys [] = $ value ;
135
135
}
136
136
}
@@ -337,7 +337,7 @@ public function getQualifiedForeignKeyName()
337
337
*/
338
338
public function getParentKey ()
339
339
{
340
- return $ this ->child ->{ $ this ->foreignKey } ;
340
+ return $ this ->getForeignKeyFrom ( $ this ->child ) ;
341
341
}
342
342
343
343
/**
@@ -371,6 +371,17 @@ protected function getRelatedKeyFrom(Model $model)
371
371
return $ model ->{$ this ->ownerKey };
372
372
}
373
373
374
+ /**
375
+ * Get the value of the model's foreign key.
376
+ *
377
+ * @param \Illuminate\Database\Eloquent\Model $model
378
+ * @return mixed
379
+ */
380
+ protected function getForeignKeyFrom (Model $ model )
381
+ {
382
+ return $ model ->{$ this ->foreignKey };
383
+ }
384
+
374
385
/**
375
386
* Get the name of the relationship.
376
387
*
0 commit comments