From 5279d82ad332503a2d08695a8b11d6f893e67f61 Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Wed, 20 Aug 2025 18:11:08 +0100 Subject: [PATCH 1/9] Add toPrettyJson method to collections --- src/Illuminate/Collections/Enumerable.php | 7 +++++++ .../Collections/Traits/EnumeratesValues.php | 10 ++++++++++ tests/Support/SupportCollectionTest.php | 13 +++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/Illuminate/Collections/Enumerable.php b/src/Illuminate/Collections/Enumerable.php index 78187b785697..e5d51af40f0a 100644 --- a/src/Illuminate/Collections/Enumerable.php +++ b/src/Illuminate/Collections/Enumerable.php @@ -1269,6 +1269,13 @@ public function jsonSerialize(): mixed; */ public function toJson($options = 0); + /** + * Get the collection of items as a pretty print formatted JSON. + * + * @return string + */ + public function toPrettyJson(); + /** * Get a CachingIterator instance. * diff --git a/src/Illuminate/Collections/Traits/EnumeratesValues.php b/src/Illuminate/Collections/Traits/EnumeratesValues.php index b3c137320148..f29606302997 100644 --- a/src/Illuminate/Collections/Traits/EnumeratesValues.php +++ b/src/Illuminate/Collections/Traits/EnumeratesValues.php @@ -984,6 +984,16 @@ public function toJson($options = 0) return json_encode($this->jsonSerialize(), $options); } + /** + * Get the collection of items as a pretty print formatted JSON. + * + * @return string + */ + public function toPrettyJson() + { + return $this->toJson(JSON_PRETTY_PRINT); + } + /** * Get a CachingIterator instance. * diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 211c7be80641..c656233b6a4f 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -653,6 +653,19 @@ public function testToJsonEncodesTheJsonSerializeResult($collection) $this->assertJsonStringEqualsJsonString(json_encode(['foo']), $results); } + #[DataProvider('collectionClassProvider')] + public function testToPrettyJsonEncodesTheJsonSerializeResult($collection) + { + $c = $this->getMockBuilder($collection)->onlyMethods(['jsonSerialize'])->getMock(); + $c->expects($this->once())->method('jsonSerialize')->willReturn(['foo' => 'bar', 'baz' => 'qux']); + $results = $c->toPrettyJson(); + $expected = json_encode(['foo' => 'bar', 'baz' => 'qux'], JSON_PRETTY_PRINT); + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + $this->assertStringContainsString("\n", $results); + $this->assertStringContainsString(" ", $results); + } + #[DataProvider('collectionClassProvider')] public function testCastingToStringJsonEncodesTheToArrayResult($collection) { From cfdaad9fee58677d02f0455624960bc552909c1d Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Wed, 20 Aug 2025 18:14:36 +0100 Subject: [PATCH 2/9] Code style fixes --- tests/Support/SupportCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index c656233b6a4f..f4fc1ae96d64 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -663,7 +663,7 @@ public function testToPrettyJsonEncodesTheJsonSerializeResult($collection) $this->assertJsonStringEqualsJsonString($expected, $results); $this->assertSame($expected, $results); $this->assertStringContainsString("\n", $results); - $this->assertStringContainsString(" ", $results); + $this->assertStringContainsString(' ', $results); } #[DataProvider('collectionClassProvider')] From 05e513b591550fc6924b95e6f3e6f0bb4b03734f Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 21 Aug 2025 10:35:05 +0100 Subject: [PATCH 3/9] Add toPrettyJson to Eloquent Model --- src/Illuminate/Database/Eloquent/Model.php | 12 ++++++++++++ tests/Database/DatabaseEloquentModelTest.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 94973c365318..b56cd9683b3d 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -1800,6 +1800,18 @@ public function toJson($options = 0) return $json; } + /** + * Convert the model instance to a pretty print formatted JSON. + * + * @return string + * + * @throws \Illuminate\Database\Eloquent\JsonEncodingException + */ + public function toPrettyJson() + { + return $this->toJson(JSON_PRETTY_PRINT); + } + /** * Convert the object into something JSON serializable. * diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index 89f21a952648..8974f65342fa 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -3414,6 +3414,18 @@ public function testModelToJsonSucceedsWithPriorErrors(): void $this->assertSame('{"name":"Mateus"}', $user->toJson(JSON_THROW_ON_ERROR)); } + public function testModelToPrettyJson(): void + { + $user = new EloquentModelStub(['name' => 'Mateus', 'active' => true]); + $results = $user->toPrettyJson(); + $expected = $user->toJson(JSON_PRETTY_PRINT); + + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + $this->assertStringContainsString("\n", $results); + $this->assertStringContainsString(' ', $results); + } + public function testFillableWithMutators() { $model = new EloquentModelWithMutators; From a97b70352e64e2705a777acc616bd8f9630b87a4 Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 21 Aug 2025 10:40:18 +0100 Subject: [PATCH 4/9] Add toPrettyJson to JsonResource --- .../Http/Resources/Json/JsonResource.php | 14 +++++++++++++- tests/Http/JsonResourceTest.php | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Resources/Json/JsonResource.php b/src/Illuminate/Http/Resources/Json/JsonResource.php index 7007507bbe45..dfadf58d2d07 100644 --- a/src/Illuminate/Http/Resources/Json/JsonResource.php +++ b/src/Illuminate/Http/Resources/Json/JsonResource.php @@ -135,7 +135,7 @@ public function toArray(Request $request) } /** - * Convert the model instance to JSON. + * Convert the resource to JSON. * * @param int $options * @return string @@ -153,6 +153,18 @@ public function toJson($options = 0) return $json; } + /** + * Convert the resource to a pretty print formatted JSON. + * + * @return string + * + * @throws \Illuminate\Database\Eloquent\JsonEncodingException + */ + public function toPrettyJson() + { + return $this->toJson(JSON_PRETTY_PRINT); + } + /** * Get any additional data that should be returned with the resource array. * diff --git a/tests/Http/JsonResourceTest.php b/tests/Http/JsonResourceTest.php index 5e1e0d029ae7..3c3b80573053 100644 --- a/tests/Http/JsonResourceTest.php +++ b/tests/Http/JsonResourceTest.php @@ -46,4 +46,23 @@ public function testJsonResourceToJsonSucceedsWithPriorErrors(): void $this->assertSame('{"foo":"bar"}', $resource->toJson(JSON_THROW_ON_ERROR)); } + + public function testJsonResourceToPrettyPrint(): void + { + $model = new class extends Model { + }; + + $resource = m::mock(JsonResource::class, ['resource' => $model]) + ->makePartial() + ->shouldReceive('jsonSerialize')->once()->andReturn(['foo' => 'bar', 'bar' => 'foo']) + ->getMock(); + + $results = $resource->toPrettyJson(); + $expected = $resource->toJson(JSON_PRETTY_PRINT); + + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + $this->assertStringContainsString("\n", $results); + $this->assertStringContainsString(' ', $results); + } } From be8f53cd6dcc7ccb572da569ff783ef1f32ae822 Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 21 Aug 2025 10:59:09 +0100 Subject: [PATCH 5/9] Add toPrettyJson to CursorPaginator, LengthAwarePaginator and Paginator --- src/Illuminate/Pagination/CursorPaginator.php | 10 +++++++++ .../Pagination/LengthAwarePaginator.php | 10 +++++++++ src/Illuminate/Pagination/Paginator.php | 10 +++++++++ tests/Pagination/CursorPaginatorTest.php | 22 +++++++++++++++++++ tests/Pagination/PaginatorTest.php | 22 +++++++++++++++++++ 5 files changed, 74 insertions(+) diff --git a/src/Illuminate/Pagination/CursorPaginator.php b/src/Illuminate/Pagination/CursorPaginator.php index e68281086ab8..e37943fa30cc 100644 --- a/src/Illuminate/Pagination/CursorPaginator.php +++ b/src/Illuminate/Pagination/CursorPaginator.php @@ -180,4 +180,14 @@ public function toJson($options = 0) { return json_encode($this->jsonSerialize(), $options); } + + /** + * Convert the object to a pretty print formatted JSON. + * + * @return string + */ + public function toPrettyJson() + { + return $this->toJson(JSON_PRETTY_PRINT); + } } diff --git a/src/Illuminate/Pagination/LengthAwarePaginator.php b/src/Illuminate/Pagination/LengthAwarePaginator.php index 40240afe7635..6f083f6c21e8 100644 --- a/src/Illuminate/Pagination/LengthAwarePaginator.php +++ b/src/Illuminate/Pagination/LengthAwarePaginator.php @@ -242,4 +242,14 @@ public function toJson($options = 0) { return json_encode($this->jsonSerialize(), $options); } + + /** + * Convert the object to a pretty print formatted JSON. + * + * @return string + */ + public function toPrettyJson() + { + return $this->toJson(JSON_PRETTY_PRINT); + } } diff --git a/src/Illuminate/Pagination/Paginator.php b/src/Illuminate/Pagination/Paginator.php index 69c9ad2f1385..27523b887002 100644 --- a/src/Illuminate/Pagination/Paginator.php +++ b/src/Illuminate/Pagination/Paginator.php @@ -185,4 +185,14 @@ public function toJson($options = 0) { return json_encode($this->jsonSerialize(), $options); } + + /** + * Convert the object to a pretty print formatted JSON. + * + * @return string + */ + public function toPrettyJson() + { + return $this->toJson(JSON_PRETTY_PRINT); + } } diff --git a/tests/Pagination/CursorPaginatorTest.php b/tests/Pagination/CursorPaginatorTest.php index 11cfb4c009a7..c97194c36200 100644 --- a/tests/Pagination/CursorPaginatorTest.php +++ b/tests/Pagination/CursorPaginatorTest.php @@ -120,6 +120,28 @@ public function testReturnEmptyCursorWhenItemsAreEmpty() ], $p->toArray()); } + public function testCursorPaginatorToJson() + { + $paginator = new CursorPaginator([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]], 2, null); + $results = $paginator->toJson(); + $expected = json_encode($paginator->toArray()); + + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + } + + public function testCursorPaginatorToPrettyJson() + { + $paginator = new CursorPaginator([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]], 2, null); + $results = $paginator->toPrettyJson(); + $expected = $paginator->toJson(JSON_PRETTY_PRINT); + + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + $this->assertStringContainsString("\n", $results); + $this->assertStringContainsString(' ', $results); + } + protected function getCursor($params, $isNext = true) { return (new Cursor($params, $isNext))->encode(); diff --git a/tests/Pagination/PaginatorTest.php b/tests/Pagination/PaginatorTest.php index 1881518d7ec7..eaa9ac341ceb 100644 --- a/tests/Pagination/PaginatorTest.php +++ b/tests/Pagination/PaginatorTest.php @@ -72,4 +72,26 @@ public function testCanTransformPaginatorItems() $this->assertInstanceOf(Paginator::class, $p); $this->assertSame(['1', '2', '3'], $p->items()); } + + public function testPaginatorToJson() + { + $p = new Paginator(['item1', 'item2', 'item3'], 3, 1); + $results = $p->toJson(); + $expected = json_encode($p->toArray()); + + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + } + + public function testPaginatorToPrettyJson() + { + $p = new Paginator(['item1', 'item2', 'item3'], 3, 1); + $results = $p->toPrettyJson(); + $expected = $p->toJson(JSON_PRETTY_PRINT); + + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + $this->assertStringContainsString("\n", $results); + $this->assertStringContainsString(' ', $results); + } } From d59eb4a4459f52874e0fbcf980ddd531871d6b06 Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 21 Aug 2025 11:03:45 +0100 Subject: [PATCH 6/9] Add toPrettyJson to Fluent --- src/Illuminate/Support/Fluent.php | 10 ++++++++++ tests/Support/SupportFluentTest.php | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Illuminate/Support/Fluent.php b/src/Illuminate/Support/Fluent.php index 085e2b44c6a3..09b0c91f859a 100755 --- a/src/Illuminate/Support/Fluent.php +++ b/src/Illuminate/Support/Fluent.php @@ -203,6 +203,16 @@ public function toJson($options = 0) return json_encode($this->jsonSerialize(), $options); } + /** + * Convert the fluent instance to a pretty print formatted JSON. + * + * @return string + */ + public function toPrettyJson() + { + return $this->toJson(JSON_PRETTY_PRINT); + } + /** * Determine if the fluent instance is empty. * diff --git a/tests/Support/SupportFluentTest.php b/tests/Support/SupportFluentTest.php index fe0edb1aedb7..a27a056cbd44 100755 --- a/tests/Support/SupportFluentTest.php +++ b/tests/Support/SupportFluentTest.php @@ -132,6 +132,19 @@ public function testToJsonEncodesTheToArrayResult() $this->assertJsonStringEqualsJsonString(json_encode(['foo']), $results); } + public function testToPrettyJson() + { + $fluent = $this->getMockBuilder(Fluent::class)->onlyMethods(['toArray'])->getMock(); + $fluent->expects($this->exactly(2))->method('toArray')->willReturn(['foo' => 'bar', 'bar' => 'foo']); + $results = $fluent->toPrettyJson(); + $expected = $fluent->toJson(JSON_PRETTY_PRINT); + + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + $this->assertStringContainsString("\n", $results); + $this->assertStringContainsString(' ', $results); + } + public function testScope() { $fluent = new Fluent(['user' => ['name' => 'taylor']]); From 15d6a3a3e4cc2d54101bfd87b5d00ff52671d6c1 Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 21 Aug 2025 11:06:07 +0100 Subject: [PATCH 7/9] Add toPrettyJson to MessageBag --- src/Illuminate/Support/MessageBag.php | 10 ++++++++++ tests/Support/SupportMessageBagTest.php | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Illuminate/Support/MessageBag.php b/src/Illuminate/Support/MessageBag.php index 24c5dadf544b..77010c9d721d 100755 --- a/src/Illuminate/Support/MessageBag.php +++ b/src/Illuminate/Support/MessageBag.php @@ -431,6 +431,16 @@ public function toJson($options = 0) return json_encode($this->jsonSerialize(), $options); } + /** + * Convert the object to a pretty print formatted JSON. + * + * @return string + */ + public function toPrettyJson() + { + return $this->toJson(JSON_PRETTY_PRINT); + } + /** * Convert the message bag to its string representation. * diff --git a/tests/Support/SupportMessageBagTest.php b/tests/Support/SupportMessageBagTest.php index af55b6d3f7c6..4aec4d92d81f 100755 --- a/tests/Support/SupportMessageBagTest.php +++ b/tests/Support/SupportMessageBagTest.php @@ -255,6 +255,21 @@ public function testMessageBagReturnsExpectedJson() $this->assertSame('{"foo":["bar"],"boom":["baz"]}', $container->toJson()); } + public function testMessageBagReturnsExpectedPrettyJson() + { + $container = new MessageBag; + $container->setFormat(':message'); + $container->add('foo', 'bar'); + $container->add('boom', 'baz'); + $results = $container->toPrettyJson(); + $expected = $container->toJson(JSON_PRETTY_PRINT); + + $this->assertJsonStringEqualsJsonString($expected, $results); + $this->assertSame($expected, $results); + $this->assertStringContainsString("\n", $results); + $this->assertStringContainsString(' ', $results); + } + public function testCountReturnsCorrectValue() { $container = new MessageBag; From a4d6610bbe767327af658a4fd8a0747399ee3639 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 21 Aug 2025 09:41:53 -0500 Subject: [PATCH 8/9] formatting --- src/Illuminate/Collections/Enumerable.php | 2 +- src/Illuminate/Collections/Traits/EnumeratesValues.php | 2 +- src/Illuminate/Database/Eloquent/Model.php | 2 +- src/Illuminate/Http/Resources/Json/JsonResource.php | 2 +- src/Illuminate/Pagination/CursorPaginator.php | 2 +- src/Illuminate/Pagination/LengthAwarePaginator.php | 2 +- src/Illuminate/Pagination/Paginator.php | 2 +- src/Illuminate/Support/Fluent.php | 2 +- src/Illuminate/Support/MessageBag.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Collections/Enumerable.php b/src/Illuminate/Collections/Enumerable.php index e5d51af40f0a..c8618e686da2 100644 --- a/src/Illuminate/Collections/Enumerable.php +++ b/src/Illuminate/Collections/Enumerable.php @@ -1270,7 +1270,7 @@ public function jsonSerialize(): mixed; public function toJson($options = 0); /** - * Get the collection of items as a pretty print formatted JSON. + * Get the collection of items as pretty print formatted JSON. * * @return string */ diff --git a/src/Illuminate/Collections/Traits/EnumeratesValues.php b/src/Illuminate/Collections/Traits/EnumeratesValues.php index f29606302997..8db326497035 100644 --- a/src/Illuminate/Collections/Traits/EnumeratesValues.php +++ b/src/Illuminate/Collections/Traits/EnumeratesValues.php @@ -985,7 +985,7 @@ public function toJson($options = 0) } /** - * Get the collection of items as a pretty print formatted JSON. + * Get the collection of items as pretty print formatted JSON. * * @return string */ diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index b56cd9683b3d..0353e7e75e1f 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -1801,7 +1801,7 @@ public function toJson($options = 0) } /** - * Convert the model instance to a pretty print formatted JSON. + * Convert the model instance to pretty print formatted JSON. * * @return string * diff --git a/src/Illuminate/Http/Resources/Json/JsonResource.php b/src/Illuminate/Http/Resources/Json/JsonResource.php index dfadf58d2d07..87cd43bdd796 100644 --- a/src/Illuminate/Http/Resources/Json/JsonResource.php +++ b/src/Illuminate/Http/Resources/Json/JsonResource.php @@ -154,7 +154,7 @@ public function toJson($options = 0) } /** - * Convert the resource to a pretty print formatted JSON. + * Convert the resource to pretty print formatted JSON. * * @return string * diff --git a/src/Illuminate/Pagination/CursorPaginator.php b/src/Illuminate/Pagination/CursorPaginator.php index e37943fa30cc..ef02b8f7b3d3 100644 --- a/src/Illuminate/Pagination/CursorPaginator.php +++ b/src/Illuminate/Pagination/CursorPaginator.php @@ -182,7 +182,7 @@ public function toJson($options = 0) } /** - * Convert the object to a pretty print formatted JSON. + * Convert the object to pretty print formatted JSON. * * @return string */ diff --git a/src/Illuminate/Pagination/LengthAwarePaginator.php b/src/Illuminate/Pagination/LengthAwarePaginator.php index 6f083f6c21e8..08976a012d68 100644 --- a/src/Illuminate/Pagination/LengthAwarePaginator.php +++ b/src/Illuminate/Pagination/LengthAwarePaginator.php @@ -244,7 +244,7 @@ public function toJson($options = 0) } /** - * Convert the object to a pretty print formatted JSON. + * Convert the object to pretty print formatted JSON. * * @return string */ diff --git a/src/Illuminate/Pagination/Paginator.php b/src/Illuminate/Pagination/Paginator.php index 27523b887002..60e4d7331765 100644 --- a/src/Illuminate/Pagination/Paginator.php +++ b/src/Illuminate/Pagination/Paginator.php @@ -187,7 +187,7 @@ public function toJson($options = 0) } /** - * Convert the object to a pretty print formatted JSON. + * Convert the object to pretty print formatted JSON. * * @return string */ diff --git a/src/Illuminate/Support/Fluent.php b/src/Illuminate/Support/Fluent.php index 09b0c91f859a..45fabc9c6b9d 100755 --- a/src/Illuminate/Support/Fluent.php +++ b/src/Illuminate/Support/Fluent.php @@ -204,7 +204,7 @@ public function toJson($options = 0) } /** - * Convert the fluent instance to a pretty print formatted JSON. + * Convert the fluent instance to pretty print formatted JSON. * * @return string */ diff --git a/src/Illuminate/Support/MessageBag.php b/src/Illuminate/Support/MessageBag.php index 77010c9d721d..bbe5a088e84e 100755 --- a/src/Illuminate/Support/MessageBag.php +++ b/src/Illuminate/Support/MessageBag.php @@ -432,7 +432,7 @@ public function toJson($options = 0) } /** - * Convert the object to a pretty print formatted JSON. + * Convert the object to pretty print formatted JSON. * * @return string */ From 6ff22c6668aecf8bf14ba6c8b8e149554a82f785 Mon Sep 17 00:00:00 2001 From: Wendell Adriel Date: Thu, 21 Aug 2025 16:22:04 +0100 Subject: [PATCH 9/9] Fix issue for test --- tests/Http/JsonResourceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Http/JsonResourceTest.php b/tests/Http/JsonResourceTest.php index 3c3b80573053..7ebf592b65a0 100644 --- a/tests/Http/JsonResourceTest.php +++ b/tests/Http/JsonResourceTest.php @@ -37,7 +37,7 @@ public function testJsonResourceToJsonSucceedsWithPriorErrors(): void $resource = m::mock(JsonResource::class, ['resource' => $model]) ->makePartial() - ->shouldReceive('jsonSerialize')->once()->andReturn(['foo' => 'bar']) + ->shouldReceive('jsonSerialize')->andReturn(['foo' => 'bar']) ->getMock(); // Simulate a JSON error @@ -54,7 +54,7 @@ public function testJsonResourceToPrettyPrint(): void $resource = m::mock(JsonResource::class, ['resource' => $model]) ->makePartial() - ->shouldReceive('jsonSerialize')->once()->andReturn(['foo' => 'bar', 'bar' => 'foo']) + ->shouldReceive('jsonSerialize')->andReturn(['foo' => 'bar', 'bar' => 'foo']) ->getMock(); $results = $resource->toPrettyJson();