Skip to content

Commit

Permalink
[8.x] The controller can directly return the stdClass object (#38033)
Browse files Browse the repository at this point in the history
* Support returning stdClass

* Add stdClass Data
  • Loading branch information
allowing committed Jul 16, 2021
1 parent d44f164 commit c46b26a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ public static function toResponse($request, $response)
$response instanceof Jsonable ||
$response instanceof ArrayObject ||
$response instanceof JsonSerializable ||
$response instanceof \stdClass ||
is_array($response))) {
$response = new JsonResponse($response);
} elseif (! $response instanceof SymfonyResponse) {
Expand Down
1 change: 1 addition & 0 deletions tests/Http/HttpJsonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function setAndRetrieveDataProvider()
'JsonSerializable data' => [new JsonResponseTestJsonSerializeObject],
'Arrayable data' => [new JsonResponseTestArrayableObject],
'Array data' => [['foo' => 'bar']],
'stdClass data' => [(object) ['foo' => 'bar']],
];
}

Expand Down

0 comments on commit c46b26a

Please sign in to comment.