Skip to content

[5.4] Document Collection::tap() method #3225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ For the remainder of this documentation, we'll discuss each method available on
[split](#method-split)
[sum](#method-sum)
[take](#method-take)
[tap](#method-tap)
[toArray](#method-toarray)
[toJson](#method-tojson)
[transform](#method-transform)
Expand Down Expand Up @@ -1260,6 +1261,20 @@ You may also pass a negative integer to take the specified amount of items from

// [4, 5]

<a name="method-tap"></a>
#### `tap()` {#collection-method}

The `tap` method passes the collection to the given callback, allowing you to "tap" into the collection at a specific point and do something with the items while not affecting the collection itself:

collect([2, 4, 3, 1, 5])
->sort()
->tap(function ($collection) {
Log::debug('Values after sorting', $collection->values()->toArray());
})
->shift();

// 1

<a name="method-toarray"></a>
#### `toArray()` {#collection-method}

Expand Down