Skip to content

Commit

Permalink
chore: Be sure to always get unique records to future-proof service
Browse files Browse the repository at this point in the history
  • Loading branch information
reganlawton committed Aug 10, 2022
1 parent 6b46f4c commit c23a6f5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/services/RelatedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public function getRelated($elementId)
/** @var Element[] $entries */
$entries = $query->all();

// dd($entries);

/** @var Query $query */
$query = Category::find();
$query->relatedTo = $element;
Expand All @@ -87,15 +89,24 @@ public function getRelated($elementId)
/** @var Element[] $users */
$users = $query->all();

/** @var Query $query */
$query = User::find();
$query->relatedTo = $element;
$query->anyStatus();
/** @var Element[] $users */
$users = $query->all();

$elements = array_merge(
$entries,
$categories,
$users,
);

return array_merge(
$matchingBlocks,
$elements
);
return collect(
array_merge(
$matchingBlocks,
$elements
)
)->unique('id')->toArray();
}
}

0 comments on commit c23a6f5

Please sign in to comment.