diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index a1e4173d5307..9b4dc4acbccf 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -882,11 +882,18 @@ public function mapSpread(callable $callback) */ public function mapToDictionary(callable $callback) { - $dictionary = $this->map($callback)->reduce(function ($groups, $pair) { - $groups[key($pair)][] = reset($pair); + $dictionary = []; - return $groups; - }, []); + $this->each(function ($item, $key) use (&$dictionary, $callback) { + $pair = $callback($item, $key); + $key = key($pair); + $value = reset($pair); + + if (! isset($dictionary[$key])) { + $dictionary[$key] = []; + } + $dictionary[$key][] = $value; + }); return new static($dictionary); }