Skip to content
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

[8.x] Added pipeInto() to Collection docs #6449

Merged
merged 1 commit into from
Oct 2, 2020
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
33 changes: 33 additions & 0 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ For the remainder of this documentation, we'll discuss each method available on
[pad](#method-pad)
[partition](#method-partition)
[pipe](#method-pipe)
[pipeInto](#method-pipeinto)
[pluck](#method-pluck)
[pop](#method-pop)
[prepend](#method-prepend)
Expand Down Expand Up @@ -1437,6 +1438,38 @@ The `pipe` method passes the collection to the given callback and returns the re

// 6

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

The `pipeInto` method creates a new instance of the given class and passes the collection into the constructor:

class ResourceCollection
{
/**
* The Collection instance.
*/
public $collection;

/**
* Create a new ResourceCollection instance.
*
* @param Collection $resource
* @return void
*/
public function __construct(Collection $collection)
{
$this->collection = $collection;
}
}

$collection = collect([1, 2, 3]);

$resource = $collection->pipeInto(ResourceCollection::class);

$resource->collection->all();

// [1, 2, 3]

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

Expand Down