Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit afab4ca

Browse files
milwad-devtaylorotwell
andauthored
[12.x] Add toPrettyJson method to collections (#10765)
* add `toPrettyJson` method to collections * Update collections.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 3c62dfd commit afab4ca

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎collections.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ For the majority of the remaining collection documentation, we'll discuss each m
230230
[times](#method-times)
231231
[toArray](#method-toarray)
232232
[toJson](#method-tojson)
233+
[toPrettyJson](#method-toprettyjson)
233234
[transform](#method-transform)
234235
[undot](#method-undot)
235236
[union](#method-union)
@@ -3333,6 +3334,17 @@ $collection->toJson();
33333334
// '{"name":"Desk", "price":200}'
33343335
```
33353336

3337+
<a name="method-toprettyjson"></a>
3338+
#### `toPrettyJson()` {.collection-method}
3339+
3340+
The `toPrettyJson` method converts the collection into a formatted JSON string using the `JSON_PRETTY_PRINT` option:
3341+
3342+
```php
3343+
$collection = collect(['name' => 'Desk', 'price' => 200]);
3344+
3345+
$collection->toPrettyJson();
3346+
```
3347+
33363348
<a name="method-transform"></a>
33373349
#### `transform()` {.collection-method}
33383350

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /