Skip to content
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
26 changes: 26 additions & 0 deletions collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1246,6 +1249,23 @@ $chunk->all();
// [4, 5, 6]
```

<a name="method-fromjson"></a>
#### `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);
```

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

Expand Down Expand Up @@ -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]);
```

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

Expand Down