From 526cc514697b1dd7f4bced7769791004eefa8c38 Mon Sep 17 00:00:00 2001 From: silai Date: Fri, 16 Jul 2021 14:18:07 +0800 Subject: [PATCH 1/2] Support returning stdClass --- src/Illuminate/Routing/Router.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Routing/Router.php b/src/Illuminate/Routing/Router.php index f6a98b6ca407..eaecb4873687 100644 --- a/src/Illuminate/Routing/Router.php +++ b/src/Illuminate/Routing/Router.php @@ -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) { From 73d4ac314472e085fb4dfc3264d1745996d59a02 Mon Sep 17 00:00:00 2001 From: silai Date: Fri, 16 Jul 2021 14:50:07 +0800 Subject: [PATCH 2/2] Add stdClass Data --- tests/Http/HttpJsonResponseTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Http/HttpJsonResponseTest.php b/tests/Http/HttpJsonResponseTest.php index 90034e3e9a0c..5fac81d570eb 100644 --- a/tests/Http/HttpJsonResponseTest.php +++ b/tests/Http/HttpJsonResponseTest.php @@ -30,6 +30,7 @@ public function setAndRetrieveDataProvider() 'JsonSerializable data' => [new JsonResponseTestJsonSerializeObject], 'Arrayable data' => [new JsonResponseTestArrayableObject], 'Array data' => [['foo' => 'bar']], + 'stdClass data' => [(object) ['foo' => 'bar']], ]; }