Skip to content

Commit 5d229eb

Browse files
committed
extractIds method returns unique ids;
1 parent 45a0c7a commit 5d229eb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Relations/MorphToMany.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,17 @@ protected function whereInMethod(Model $model, $key)
393393
*
394394
* @return mixed
395395
*/
396-
private function extractIds(array $data, ?string $relatedPivotKey = null)
396+
public function extractIds(array $data, ?string $relatedPivotKey = null)
397397
{
398398
$relatedPivotKey = $relatedPivotKey ?: $this->relatedPivotKey;
399-
return array_reduce($data, function ($carry, $item) use ($relatedPivotKey) {
399+
$result = array_reduce($data, function ($carry, $item) use ($relatedPivotKey) {
400400
if (is_array($item) && array_key_exists($relatedPivotKey, $item)) {
401401
$carry[] = $item[$relatedPivotKey];
402402
}
403403

404404
return $carry;
405405
}, []);
406+
407+
return array_values(array_unique($result));
406408
}
407409
}

0 commit comments

Comments
 (0)