From 844cdef55a06e354b928b33e46c782561adebb43 Mon Sep 17 00:00:00 2001 From: Douglas Medeiros Date: Fri, 24 Feb 2023 16:27:31 -0300 Subject: [PATCH 1/2] feat: add dot method in collection --- src/Illuminate/Collections/Collection.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index aa12217dafb1..3ee0ccd002fb 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -1577,6 +1577,16 @@ public function undot() return new static(Arr::undot($this->all())); } + /** + * Flatten a multi-dimensional associative array with dots. + * + * @return static + */ + public function dot() + { + return new static(Arr::dot($this->all())); + } + /** * Return only unique items from the collection array. * From 685f1974783e40683295bc6eac6eb92dfe7d9980 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 25 Feb 2023 01:10:26 +0530 Subject: [PATCH 2/2] formatting --- src/Illuminate/Collections/Collection.php | 12 ++++++------ src/Illuminate/Collections/LazyCollection.php | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index 3ee0ccd002fb..9e6092076cdb 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -1568,23 +1568,23 @@ public function transform(callable $callback) } /** - * Convert a flatten "dot" notation array into an expanded array. + * Flatten a multi-dimensional associative array with dots. * * @return static */ - public function undot() + public function dot() { - return new static(Arr::undot($this->all())); + return new static(Arr::dot($this->all())); } /** - * Flatten a multi-dimensional associative array with dots. + * Convert a flatten "dot" notation array into an expanded array. * * @return static */ - public function dot() + public function undot() { - return new static(Arr::dot($this->all())); + return new static(Arr::undot($this->all())); } /** diff --git a/src/Illuminate/Collections/LazyCollection.php b/src/Illuminate/Collections/LazyCollection.php index 8119b3af230c..1b7830180df9 100644 --- a/src/Illuminate/Collections/LazyCollection.php +++ b/src/Illuminate/Collections/LazyCollection.php @@ -1518,6 +1518,16 @@ public function tapEach(callable $callback) }); } + /** + * Flatten a multi-dimensional associative array with dots. + * + * @return static + */ + public function dot() + { + return $this->passthru('dot', []); + } + /** * Convert a flatten "dot" notation array into an expanded array. *