@@ -63,32 +63,32 @@ protected function applyJoinSearchConditions($query, $likeOperator, $value)
6363 $ relatedModel = $ this ->belongsToField ->getRelatedModel ($ this ->repository );
6464 $ relatedTable = $ relatedModel ->getTable ();
6565 $ parentTable = $ this ->repository ->model ()->getTable ();
66-
66+
6767 $ localKey = $ this ->belongsToField ->getQualifiedKey ($ this ->repository );
6868 $ foreignKeyName = $ relatedModel ->getKeyName ();
69-
69+
7070 // Use a consistent alias based on the relationship name to reuse joins
7171 $ relationshipName = $ this ->belongsToField ->getAttribute ();
7272 $ joinAlias = "{$ relatedTable }_for_ {$ relationshipName }" ;
73-
73+
7474 // Check if this exact join already exists
7575 $ existingJoins = collect ($ query ->getQuery ()->joins ?? []);
7676 $ joinExists = $ existingJoins ->contains (function ($ join ) use ($ joinAlias , $ relatedTable ) {
77- return $ join ->table === "{$ relatedTable } as {$ joinAlias }" ||
77+ return $ join ->table === "{$ relatedTable } as {$ joinAlias }" ||
7878 str_contains ($ join ->table , $ joinAlias );
7979 });
80-
81- if (!$ joinExists ) {
80+
81+ if (! $ joinExists ) {
8282 $ query ->leftJoin ("{$ relatedTable } as {$ joinAlias }" , function ($ join ) use ($ localKey , $ joinAlias , $ foreignKeyName ) {
8383 $ join ->on ($ localKey , '= ' , "{$ joinAlias }. {$ foreignKeyName }" );
8484 });
8585 }
86-
86+
8787 // Apply search conditions for each searchable attribute
8888 collect ($ this ->belongsToField ->getSearchables ())->each (function (string $ attribute ) use ($ query , $ likeOperator , $ value , $ joinAlias ) {
8989 $ qualifiedAttribute = "{$ joinAlias }. {$ attribute }" ;
90-
91- if (!config ('restify.search.case_sensitive ' )) {
90+
91+ if (! config ('restify.search.case_sensitive ' )) {
9292 $ upper = strtoupper ($ value );
9393 $ query ->orWhereRaw ("UPPER( {$ qualifiedAttribute }) LIKE ? " , ['% ' .$ upper .'% ' ]);
9494 } else {
@@ -113,5 +113,4 @@ protected function applySubquerySearchConditions($query, $likeOperator, $value)
113113 );
114114 });
115115 }
116-
117116}
0 commit comments