Skip to content

Commit 75410d7

Browse files
committed
resolve closures via app
1 parent 1f84639 commit 75410d7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function resolveArrayableProperties(array $props, Request $request, bool
187187
}
188188

189189
if ($value instanceof Closure) {
190-
$value = $value();
190+
$value = App::call($value);
191191
}
192192

193193
if ($unpackDotProps && str_contains($key, '.')) {

tests/ResponseFactoryTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,27 @@ public function test_dot_props_are_merged_from_shared(): void
176176
]);
177177
}
178178

179+
public function test_shared_data_can_resolve_closure_arguments(): void
180+
{
181+
Inertia::share('query', fn (HttpRequest $request) => $request->query());
182+
183+
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
184+
return Inertia::render('User/Edit');
185+
});
186+
187+
$response = $this->withoutExceptionHandling()->get('/?foo=bar', ['X-Inertia' => 'true']);
188+
189+
$response->assertSuccessful();
190+
$response->assertJson([
191+
'component' => 'User/Edit',
192+
'props' => [
193+
'query' => [
194+
'foo' => 'bar',
195+
],
196+
],
197+
]);
198+
}
199+
179200
public function test_dot_props_with_callbacks_are_merged_from_shared(): void
180201
{
181202
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {

0 commit comments

Comments
 (0)