@@ -259,8 +259,8 @@ protected function getPropertiesFromMethods($model)
259259 $ methods = get_class_methods ($ model );
260260
261261 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
264264 $ reflection = new \ReflectionMethod ($ model , $ method );
265265 $ file = new \SplFileObject ($ reflection ->getFileName ());
266266 $ file ->seek ($ reflection ->getStartLine () - 1 );
@@ -272,22 +272,13 @@ protected function getPropertiesFromMethods($model)
272272 $ code = trim (preg_replace ('/\s\s+/ ' , '' , $ code ));
273273 $ begin = strpos ($ code , 'function( ' );
274274 $ code = substr ($ code , $ begin , strrpos ($ code , '} ' ) - $ begin + 1 );
275- foreach (array (
276- 'belongsTo ' ,
277- ) as $ relation ) {
275+ foreach (['belongsTo ' ] as $ relation ) {
278276 $ search = '$this-> ' . $ relation . '( ' ;
279277 if ($ pos = stripos ($ code , $ search )) {
280- //Resolve the relation's model to a Relation object.
281278 $ relationObj = $ model ->$ method ();
282279 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) ' );
291282 }
292283 }
293284 }
@@ -301,7 +292,7 @@ protected function getPropertiesFromMethods($model)
301292 */
302293 protected function setProperty ($ name , $ type = null , $ table = null )
303294 {
304- if ($ type !== null && Str::startsWith ($ type , 'function ( ' )) {
295+ if ($ type !== null && Str::startsWith ($ type , 'factory ( ' )) {
305296 $ this ->properties [$ name ] = $ type ;
306297
307298 return ;
0 commit comments