Skip to content

Commit 1bcdc24

Browse files
[10.x] Add "dot" method to Illuminate\Support\Collection class (#46265)
* feat: add dot method in collection * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0a19746 commit 1bcdc24

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,16 @@ public function transform(callable $callback)
15671567
return $this;
15681568
}
15691569

1570+
/**
1571+
* Flatten a multi-dimensional associative array with dots.
1572+
*
1573+
* @return static
1574+
*/
1575+
public function dot()
1576+
{
1577+
return new static(Arr::dot($this->all()));
1578+
}
1579+
15701580
/**
15711581
* Convert a flatten "dot" notation array into an expanded array.
15721582
*

src/Illuminate/Collections/LazyCollection.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,16 @@ public function tapEach(callable $callback)
15181518
});
15191519
}
15201520

1521+
/**
1522+
* Flatten a multi-dimensional associative array with dots.
1523+
*
1524+
* @return static
1525+
*/
1526+
public function dot()
1527+
{
1528+
return $this->passthru('dot', []);
1529+
}
1530+
15211531
/**
15221532
* Convert a flatten "dot" notation array into an expanded array.
15231533
*

0 commit comments

Comments
 (0)