Skip to content

Commit

Permalink
#added-ignore-scopes-in-connectives-func
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehmet Akif TEZCAN committed Feb 28, 2024
1 parent 0764c06 commit 110366f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/Traits/Connective.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function connections(string|array|null $connectionTypes = null, string|ar
/**
* @return ConnectiveCollection<ConnectiveContract>|null
*/
public function connectives(string|array|null $connectionTypes = null, string|array|null $modelTypes = null): ?ConnectiveCollection
public function connectives(string|array|null $connectionTypes = null, string|array|null $modelTypes = null, array|null $ignoreScopes = []): ?ConnectiveCollection
{
$connections = $this->connections($connectionTypes, $modelTypes);
$collection = ConnectiveCollection::make();
Expand All @@ -86,8 +86,13 @@ public function connectives(string|array|null $connectionTypes = null, string|ar
$toModelType = $connection->to_model_type;
$toModelId = $connection->to_model_id;

$toModelInstance = $toModelType::find($toModelId);
$collection->push($toModelInstance);
if ($ignoreScopes && is_array($ignoreScopes)){
$toModelInstance = $toModelType::withoutGlobalScopes($ignoreScopes)->find($toModelId);
$collection->push($toModelInstance);
}else{
$toModelInstance = $toModelType::find($toModelId);
$collection->push($toModelInstance);
}
}

return $collection;
Expand Down Expand Up @@ -122,7 +127,7 @@ public function inverseConnections(string|array|null $connectionTypes = null, st
/**
* @return ConnectiveCollection<ConnectiveContract>|null
*/
public function inverseConnectives(string|array|null $connectionTypes = null, string|array|null $modelTypes = null): ?ConnectiveCollection
public function inverseConnectives(string|array|null $connectionTypes = null, string|array|null $modelTypes = null, array|null $ignoreScopes = []): ?ConnectiveCollection
{
$incomingConnections = $this->inverseConnections($connectionTypes, $modelTypes);
$collection = ConnectiveCollection::make();
Expand All @@ -131,8 +136,14 @@ public function inverseConnectives(string|array|null $connectionTypes = null, st
$fromModelType = $incomingConnection->from_model_type;
$fromModelId = $incomingConnection->from_model_id;

$fromModelInstance = $fromModelType::find($fromModelId);
$collection->push($fromModelInstance);
if ($ignoreScopes && is_array($ignoreScopes)){
$fromModelInstance = $fromModelType::withoutGlobalScopes($ignoreScopes)->find($fromModelId);
$collection->push($fromModelInstance);
}else{
$fromModelInstance = $fromModelType::find($fromModelId);
$collection->push($fromModelInstance);
}

}

return $collection;
Expand Down

0 comments on commit 110366f

Please sign in to comment.