File tree Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Expand file tree Collapse file tree 1 file changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -710,7 +710,8 @@ public static function loadRelationsAttributesRecursive(Model $model)
710710 if (method_exists ($ model , $ key )) {
711711 $ reflection_method = new ReflectionMethod ($ model , $ key );
712712
713- if ($ reflection_method ->class != "Illuminate\Database\Eloquent\Model " ) {
713+ // Check if method class has or inherits Illuminate\Database\Eloquent\Model
714+ if (!static ::isClassInClass ("Illuminate\Database\Eloquent\Model " , $ reflection_method ->class )) {
714715 $ relation = $ model ->$ key ();
715716
716717 if ($ relation instanceof Relation) {
@@ -778,4 +779,36 @@ private static function isMultiLevelArray(array $array)
778779 }
779780 return true ;
780781 }
782+
783+ /**
784+ * Check the hierarchy of the given class (including the given class itself)
785+ * to find out if the class is part of the other class.
786+ *
787+ * @param string $classNeedle
788+ * @param string $classHaystack
789+ * @return bool
790+ */
791+ private static function isClassInClass ($ classNeedle , $ classHaystack )
792+ {
793+ // Check for the same
794+ if ($ classNeedle == $ classHaystack ) {
795+ return true ;
796+ }
797+
798+ // Check for parent
799+ $ classHaystackReflected = new \ReflectionClass ($ classHaystack );
800+ while ($ parent = $ classHaystackReflected ->getParentClass ()) {
801+ /**
802+ * @var \ReflectionClass $parent
803+ */
804+ if ($ parent ->getName () == $ classNeedle ) {
805+ return true ;
806+ }
807+ $ classHaystackReflected = $ parent ;
808+ }
809+
810+ return false ;
811+
812+ }
813+
781814}
You can’t perform that action at this time.
0 commit comments