@@ -77,7 +77,7 @@ public function connections(string|array|null $connectionTypes = null, string|ar
7777 /**
7878 * @return ConnectiveCollection<ConnectiveContract>|null
7979 */
80- public function connectives (string |array |null $ connectionTypes = null , string |array |null $ modelTypes = null ): ?ConnectiveCollection
80+ public function connectives (string |array |null $ connectionTypes = null , string |array |null $ modelTypes = null , ? array $ ignoreScopes = [] ): ?ConnectiveCollection
8181 {
8282 $ connections = $ this ->connections ($ connectionTypes , $ modelTypes );
8383 $ collection = ConnectiveCollection::make ();
@@ -86,8 +86,16 @@ public function connectives(string|array|null $connectionTypes = null, string|ar
8686 $ toModelType = $ connection ->to_model_type ;
8787 $ toModelId = $ connection ->to_model_id ;
8888
89- $ toModelInstance = $ toModelType ::find ($ toModelId );
90- $ collection ->push ($ toModelInstance );
89+ if ($ ignoreScopes && is_array ($ ignoreScopes )) {
90+ $ toModelInstance = $ toModelType ::withoutGlobalScopes ($ ignoreScopes )->find ($ toModelId );
91+ } else {
92+ $ toModelInstance = $ toModelType ::find ($ toModelId );
93+ }
94+
95+ if ($ toModelInstance != null ) {
96+ $ collection ->push ($ toModelInstance );
97+ }
98+
9199 }
92100
93101 return $ collection ;
@@ -122,7 +130,7 @@ public function inverseConnections(string|array|null $connectionTypes = null, st
122130 /**
123131 * @return ConnectiveCollection<ConnectiveContract>|null
124132 */
125- public function inverseConnectives (string |array |null $ connectionTypes = null , string |array |null $ modelTypes = null ): ?ConnectiveCollection
133+ public function inverseConnectives (string |array |null $ connectionTypes = null , string |array |null $ modelTypes = null , ? array $ ignoreScopes = [] ): ?ConnectiveCollection
126134 {
127135 $ incomingConnections = $ this ->inverseConnections ($ connectionTypes , $ modelTypes );
128136 $ collection = ConnectiveCollection::make ();
@@ -131,8 +139,16 @@ public function inverseConnectives(string|array|null $connectionTypes = null, st
131139 $ fromModelType = $ incomingConnection ->from_model_type ;
132140 $ fromModelId = $ incomingConnection ->from_model_id ;
133141
134- $ fromModelInstance = $ fromModelType ::find ($ fromModelId );
135- $ collection ->push ($ fromModelInstance );
142+ if ($ ignoreScopes && is_array ($ ignoreScopes )) {
143+ $ fromModelInstance = $ fromModelType ::withoutGlobalScopes ($ ignoreScopes )->find ($ fromModelId );
144+ } else {
145+ $ fromModelInstance = $ fromModelType ::find ($ fromModelId );
146+ }
147+
148+ if ($ fromModelInstance != null ) {
149+ $ collection ->push ($ fromModelInstance );
150+ }
151+
136152 }
137153
138154 return $ collection ;
0 commit comments