Skip to content

Commit cbb7077

Browse files
committed
wip
1 parent 5edda49 commit cbb7077

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/Inertia.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**
88
* @method static void setRootView(string $name)
9-
* @method static void share(string|array<string, mixed>|\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|\Inertia\ProvidesInertiaProperties $key, mixed $value = null)
9+
* @method static void share(string|array<array-key, mixed>|\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|\Inertia\ProvidesInertiaProperties $key, mixed $value = null)
1010
* @method static mixed getShared(string|null $key = null, mixed $default = null)
1111
* @method static void clearHistory()
1212
* @method static void encryptHistory($encrypt = true)

src/ResponseFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function setRootView(string $name): void
7676
* included with every response, making it ideal for user authentication
7777
* state, flash messages, etc.
7878
*
79-
* @param string|array<string, mixed>|\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|\Inertia\ProvidesInertiaProperties $key
79+
* @param string|array<array-key, mixed>|\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|\Inertia\ProvidesInertiaProperties $key
8080
* @param mixed $value
8181
*/
8282
public function share($key, $value = null): void

tests/ResponseFactoryTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,42 @@ public function toInertiaProperties(RenderContext $context): iterable
439439
]);
440440
}
441441

442+
public function test_can_share_arrays_containing_provides_inertia_props(): void
443+
{
444+
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
445+
Inertia::share([
446+
'regular' => 'shared_prop',
447+
new class implements ProvidesInertiaProperties
448+
{
449+
/**
450+
* @return array<string, mixed>
451+
*/
452+
public function toInertiaProperties(RenderContext $context): iterable
453+
{
454+
return [
455+
'from_object' => 'shared_value',
456+
];
457+
}
458+
},
459+
]);
460+
461+
return Inertia::render('User/Edit', [
462+
'component' => 'prop',
463+
]);
464+
});
465+
466+
$response = $this->withoutExceptionHandling()->get('/', ['X-Inertia' => 'true']);
467+
$response->assertSuccessful();
468+
$response->assertJson([
469+
'component' => 'User/Edit',
470+
'props' => [
471+
'regular' => 'shared_prop',
472+
'from_object' => 'shared_value',
473+
'component' => 'prop',
474+
],
475+
]);
476+
}
477+
442478
public function test_will_throw_exception_if_component_does_not_exist_when_ensuring_is_enabled(): void
443479
{
444480
config()->set('inertia.ensure_pages_exist', true);

0 commit comments

Comments
 (0)