Skip to content

Commit

Permalink
Merge pull request #6449 from pascalbaljet/patch-2
Browse files Browse the repository at this point in the history
[8.x] Added pipeInto() to Collection docs
  • Loading branch information
taylorotwell authored Oct 2, 2020
2 parents fb7f37c + e24d639 commit 2e775d8
Showing 1 changed file with 33 additions and 0 deletions.
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

0 comments on commit 2e775d8

Please sign in to comment.