66use Illuminate \Database \Eloquent \Model ;
77use Illuminate \Database \Eloquent \Relations \Relation ;
88use Illuminate \Support \Arr ;
9- use Illuminate \Support \Str ;
109use Spatie \QueryBuilder \Exceptions \InvalidFilterProperty ;
1110
1211/**
@@ -45,15 +44,15 @@ protected function getRelatedModel(Model $modelQuery, string $relationName, stri
4544 {
4645 if ($ relationParent ) {
4746 $ modelParent = $ this ->getModelFromRelation ($ modelQuery , $ relationParent );
48- if (!$ modelParent ) {
47+ if (! $ modelParent ) {
4948 throw InvalidFilterProperty::make ($ relationParent .'. ' .$ relationName );
5049 }
5150 } else {
5251 $ modelParent = $ modelQuery ;
5352 }
5453
5554 $ relatedModel = $ this ->getRelatedModelFromRelation ($ modelParent , $ relationName );
56- if (!$ relatedModel ) {
55+ if (! $ relatedModel ) {
5756 throw InvalidFilterProperty::make ($ relationParent .'. ' .$ relationName );
5857 }
5958
@@ -62,17 +61,17 @@ protected function getRelatedModel(Model $modelQuery, string $relationName, stri
6261
6362 protected function getRelatedModelFromRelation (Model $ model , string $ relationName ): ?Model
6463 {
65- if (!method_exists ($ model , $ relationName )) {
64+ if (! method_exists ($ model , $ relationName )) {
6665 return null ;
6766 }
6867
6968 $ relationObject = $ model ->$ relationName ();
70- if (!is_subclass_of ($ relationObject , Relation::class)) {
69+ if (! is_subclass_of ($ relationObject , Relation::class)) {
7170 return null ;
7271 }
7372
7473 $ relatedModel = $ relationObject ->getRelated ();
75- if (!is_subclass_of ($ relatedModel , Model::class)) {
74+ if (! is_subclass_of ($ relatedModel , Model::class)) {
7675 return null ;
7776 }
7877
@@ -87,9 +86,10 @@ protected function getModelFromRelation(Model $model, string $relation, int $lev
8786 } else {
8887 $ firstRelation = $ relationParts [0 ];
8988 $ firstRelatedModel = $ this ->getRelatedModelFromRelation ($ model , $ firstRelation );
90- if (!$ firstRelatedModel ) {
89+ if (! $ firstRelatedModel ) {
9190 return null ;
9291 }
92+
9393 return $ this ->getModelFromRelation ($ firstRelatedModel , implode ('. ' , array_slice ($ relationParts , 1 )), $ level + 1 );
9494 }
9595 }
0 commit comments