File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/Illuminate/Foundation
tests/Integration/Foundation Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -1444,4 +1444,17 @@ public function preventQueriesWhilePreparingResponse($connection = null)
1444
1444
1445
1445
return $ this ;
1446
1446
}
1447
+
1448
+ /**
1449
+ * Restores ability for database to query while preparing the request response.
1450
+ *
1451
+ * @param string|null $connection
1452
+ * @return $this
1453
+ */
1454
+ public function allowQueriesWhilePreparingResponse ($ connection = null )
1455
+ {
1456
+ $ this ['events ' ]->listen (PreparingResponse::class, fn () => $ this ['db ' ]->connection ($ connection )->allowQueries ());
1457
+
1458
+ return $ this ;
1459
+ }
1447
1460
}
Original file line number Diff line number Diff line change @@ -97,6 +97,31 @@ public function toArray($request)
97
97
98
98
$ this ->assertCount (1 , DB ::getQueryLog ());
99
99
}
100
+
101
+ public function testItcanRestoreValue ()
102
+ {
103
+ Schema::create ('foo ' , function ($ table ) {
104
+ $ table ->id ();
105
+ });
106
+ Route::get ('test-route ' , function () {
107
+ return new class ('xxxx ' ) extends JsonResource {
108
+ public function toArray ($ request )
109
+ {
110
+ return [
111
+ //
112
+ ];
113
+ }
114
+ };
115
+ })->middleware (TestMiddleware::class);
116
+ DB ::enableQueryLog ();
117
+ $ this ->withoutExceptionHandling ();
118
+
119
+ $ this ->app ->preventQueriesWhilePreparingResponse ();
120
+ $ this ->app ->allowQueriesWhilePreparingResponse ();
121
+ $ this ->get ('test-route ' )->assertOk ();
122
+
123
+ $ this ->assertCount (1 , DB ::getQueryLog ());
124
+ }
100
125
}
101
126
102
127
class TestMiddleware
You can’t perform that action at this time.
0 commit comments