@@ -452,6 +452,8 @@ protected function getPropertiesFromMethods($model)
452452 ) {
453453 //Use reflection to inspect the code, based on Illuminate/Support/SerializableClosure.php
454454 $ reflection = new \ReflectionMethod ($ model , $ method );
455+ // php 7.x type or fallback to docblock
456+ $ type = (string ) $ reflection ->getReturnType () ?: $ this ->getReturnTypeFromDocBlock ($ reflection );
455457
456458 $ file = new \SplFileObject ($ reflection ->getFileName ());
457459 $ file ->seek ($ reflection ->getStartLine () - 1 );
@@ -466,19 +468,19 @@ protected function getPropertiesFromMethods($model)
466468 $ code = substr ($ code , $ begin , strrpos ($ code , '} ' ) - $ begin + 1 );
467469
468470 foreach (array (
469- 'hasMany ' ,
470- 'hasManyThrough ' ,
471- 'belongsToMany ' ,
472- 'hasOne ' ,
473- 'belongsTo ' ,
474- 'morphOne ' ,
475- 'morphTo ' ,
476- 'morphMany ' ,
477- 'morphToMany ' ,
478- 'morphedByMany '
479- ) as $ relation ) {
471+ 'hasMany ' => ' \Illuminate\Database\Eloquent\Relations\HasMany ' ,
472+ 'hasManyThrough ' => ' \Illuminate\Database\Eloquent\Relations\HasManyThrough ' ,
473+ 'belongsToMany ' => ' \Illuminate\Database\Eloquent\Relations\BelongsToMany ' ,
474+ 'hasOne ' => ' \Illuminate\Database\Eloquent\Relations\HasOne ' ,
475+ 'belongsTo ' => ' \Illuminate\Database\Eloquent\Relations\BelongsTo ' ,
476+ 'morphOne ' => ' \Illuminate\Database\Eloquent\Relations\MorphOne ' ,
477+ 'morphTo ' => ' \Illuminate\Database\Eloquent\Relations\MorphTo ' ,
478+ 'morphMany ' => ' \Illuminate\Database\Eloquent\Relations\MorphMany ' ,
479+ 'morphToMany ' => ' \Illuminate\Database\Eloquent\Relations\MorphToMany ' ,
480+ 'morphedByMany ' => ' \Illuminate\Database\Eloquent\Relations\MorphToMany '
481+ ) as $ relation => $ impl ) {
480482 $ search = '$this-> ' . $ relation . '( ' ;
481- if ($ pos = stripos ($ code , $ search ) ) {
483+ if (stripos ( $ code , $ search ) || stripos ($ impl , $ type ) !== false ) {
482484 //Resolve the relation's model to a Relation object.
483485 $ methodReflection = new \ReflectionMethod ($ model , $ method );
484486 if ($ methodReflection ->getNumberOfParameters ()) {
0 commit comments