From e24d6395424ed90fc22702c830e6b24377a981f3 Mon Sep 17 00:00:00 2001 From: Pascal Baljet Date: Fri, 2 Oct 2020 20:14:15 +0200 Subject: [PATCH] Added pipeInto() to Collection docs --- collections.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/collections.md b/collections.md index b80ab539f1..436f627375 100644 --- a/collections.md +++ b/collections.md @@ -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) @@ -1437,6 +1438,38 @@ The `pipe` method passes the collection to the given callback and returns the re // 6 + +#### `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] + #### `pluck()` {#collection-method}