@@ -259,8 +259,8 @@ protected function getPropertiesFromMethods($model)
259
259
$ methods = get_class_methods ($ model );
260
260
261
261
foreach ($ methods as $ method ) {
262
- if (!method_exists ('Illuminate\Database\Eloquent\Model ' , $ method) && !Str:: startsWith ( $ method , ' get ' )) {
263
- //Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
262
+ if (!Str:: startsWith ( $ method , ' get ' ) && ! method_exists ('Illuminate\Database\Eloquent\Model ' , $ method )) {
263
+ // Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
264
264
$ reflection = new \ReflectionMethod ($ model , $ method );
265
265
$ file = new \SplFileObject ($ reflection ->getFileName ());
266
266
$ file ->seek ($ reflection ->getStartLine () - 1 );
@@ -272,22 +272,13 @@ protected function getPropertiesFromMethods($model)
272
272
$ code = trim (preg_replace ('/\s\s+/ ' , '' , $ code ));
273
273
$ begin = strpos ($ code , 'function( ' );
274
274
$ code = substr ($ code , $ begin , strrpos ($ code , '} ' ) - $ begin + 1 );
275
- foreach (array (
276
- 'belongsTo ' ,
277
- ) as $ relation ) {
275
+ foreach (['belongsTo ' ] as $ relation ) {
278
276
$ search = '$this-> ' . $ relation . '( ' ;
279
277
if ($ pos = stripos ($ code , $ search )) {
280
- //Resolve the relation's model to a Relation object.
281
278
$ relationObj = $ model ->$ method ();
282
279
if ($ relationObj instanceof Relation) {
283
- $ relatedModel = '\\' . get_class ($ relationObj ->getRelated ());
284
- $ relatedObj = new $ relatedModel ;
285
- $ property = method_exists ($ relationObj , 'getForeignKeyName ' )
286
- ? $ relationObj ->getForeignKeyName ()
287
- : $ relationObj ->getForeignKey ();
288
- $ this ->setProperty ($ property , 'function () {
289
- return factory( ' . get_class ($ relationObj ->getRelated ()) . '::class)->create()-> ' . $ relatedObj ->getKeyName () . ';
290
- } ' );
280
+ echo 'found method: ' , $ method , PHP_EOL ;
281
+ $ this ->setProperty ($ relationObj ->getForeignKeyName (), 'factory( ' . get_class ($ relationObj ->getRelated ()) . '::class) ' );
291
282
}
292
283
}
293
284
}
@@ -301,7 +292,7 @@ protected function getPropertiesFromMethods($model)
301
292
*/
302
293
protected function setProperty ($ name , $ type = null , $ table = null )
303
294
{
304
- if ($ type !== null && Str::startsWith ($ type , 'function ( ' )) {
295
+ if ($ type !== null && Str::startsWith ($ type , 'factory ( ' )) {
305
296
$ this ->properties [$ name ] = $ type ;
306
297
307
298
return ;
0 commit comments