Skip to content

Commit 141256b

Browse files
committed
fixed dot config merging
1 parent 31fed76 commit 141256b

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/Response.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ public function resolveArrayableProperties(array $props, Request $request, bool
172172
$value = $this->resolveArrayableProperties($value, $request, false);
173173
}
174174

175+
if ($value instanceof Closure) {
176+
$value = $value();
177+
}
178+
175179
if ($unpackDotProps && str_contains($key, '.')) {
176180
Arr::set($props, $key, $value);
177181
unset($props[$key]);

tests/ResponseFactoryTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,66 @@ public function test_shared_data_can_be_shared_from_anywhere(): void
146146
]);
147147
}
148148

149+
public function test_dot_props_are_merged_from_shared(): void
150+
{
151+
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
152+
Inertia::share('auth.user', [
153+
'name' => 'Jonathan',
154+
]);
155+
156+
return Inertia::render('User/Edit', [
157+
'auth.user.can.create_group' => false,
158+
]);
159+
});
160+
161+
$response = $this->withoutExceptionHandling()->get('/', ['X-Inertia' => 'true']);
162+
163+
$response->assertSuccessful();
164+
$response->assertJson([
165+
'component' => 'User/Edit',
166+
'props' => [
167+
'auth' => [
168+
'user' => [
169+
'name' => 'Jonathan',
170+
'can' => [
171+
'create_group' => false,
172+
],
173+
],
174+
],
175+
],
176+
]);
177+
}
178+
179+
public function test_dot_props_with_callbacks_are_merged_from_shared(): void
180+
{
181+
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
182+
Inertia::share('auth.user', fn () => [
183+
'name' => 'Jonathan',
184+
]);
185+
186+
return Inertia::render('User/Edit', [
187+
'auth.user.can.create_group' => false,
188+
]);
189+
});
190+
191+
$response = $this->withoutExceptionHandling()->get('/', ['X-Inertia' => 'true']);
192+
193+
$response->assertSuccessful();
194+
$response->assertJson([
195+
'component' => 'User/Edit',
196+
'props' => [
197+
'auth' => [
198+
'user' => [
199+
'name' => 'Jonathan',
200+
'can' => [
201+
'create_group' => false,
202+
],
203+
],
204+
],
205+
],
206+
]);
207+
}
208+
149209
public function test_can_flush_shared_data(): void
150210
{
151211
Inertia::share('foo', 'bar');

0 commit comments

Comments
 (0)