diff --git a/collections.md b/collections.md index 9cf8a828d5c..d1a11fe3c33 100644 --- a/collections.md +++ b/collections.md @@ -35,6 +35,8 @@ As mentioned above, the `collect` helper returns a new `Illuminate\Support\Colle $collection = collect([1, 2, 3]); ``` +You may also create a collection using the [make](#method-make) and [fromJson](#method-fromjson) methods. + > [!NOTE] > The results of [Eloquent](/docs/{{version}}/eloquent) queries are always returned as `Collection` instances. @@ -144,6 +146,7 @@ For the majority of the remaining collection documentation, we'll discuss each m [flip](#method-flip) [forget](#method-forget) [forPage](#method-forpage) +[fromJson](#method-fromjson) [get](#method-get) [groupBy](#method-groupby) [has](#method-has) @@ -1246,6 +1249,23 @@ $chunk->all(); // [4, 5, 6] ``` + +#### `fromJson()` {.collection-method} + +The static `fromJson` method creates a new collection instance by decoding a given JSON string using the `json_decode` PHP function: + +```php +use Illuminate\Support\Collection; + +$json = json_encode([ + 'name' => 'Taylor Otwell', + 'role' => 'Developer', + 'status' => 'Active', +]); + +$collection = Collection::fromJson($json); +``` + #### `get()` {.collection-method} @@ -1697,6 +1717,12 @@ The static `macro` method allows you to add methods to the `Collection` class at The static `make` method creates a new collection instance. See the [Creating Collections](#creating-collections) section. +```php +use Illuminate\Support\Collection; + +$collection = Collection::make([1, 2, 3]); +``` + #### `map()` {.collection-method}