Skip to content

Commit 3ab0f1a

Browse files
authored
Fix incorrect type hint in render method (#353)
Co-authored-by: Rhys <[email protected]>
1 parent 7f06e9b commit 3ab0f1a

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/ResponseFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ public function lazy(callable $callback): LazyProp
8585
return new LazyProp($callback);
8686
}
8787

88-
public function render($component, array $props = []): Response
88+
/**
89+
* @param string $component
90+
* @param array|Arrayable $props
91+
*/
92+
public function render($component, $props = []): Response
8993
{
9094
if ($props instanceof Arrayable) {
9195
$props = $props->toArray();

tests/ResponseFactoryTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Inertia\Tests;
44

5+
use Illuminate\Contracts\Support\Arrayable;
56
use Illuminate\Http\RedirectResponse;
67
use Illuminate\Http\Response;
78
use Illuminate\Session\Middleware\StartSession;
@@ -131,4 +132,30 @@ public function test_can_create_lazy_prop(): void
131132

132133
$this->assertInstanceOf(LazyProp::class, $lazyProp);
133134
}
135+
136+
public function test_will_accept_arrayabe_props()
137+
{
138+
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
139+
Inertia::share('foo', 'bar');
140+
141+
return Inertia::render('User/Edit', new class implements Arrayable
142+
{
143+
public function toArray()
144+
{
145+
return [
146+
'foo' => 'bar',
147+
];
148+
}
149+
});
150+
});
151+
152+
$response = $this->withoutExceptionHandling()->get('/', ['X-Inertia' => 'true']);
153+
$response->assertSuccessful();
154+
$response->assertJson([
155+
'component' => 'User/Edit',
156+
'props' => [
157+
'foo' => 'bar',
158+
],
159+
]);
160+
}
134161
}

0 commit comments

Comments
 (0)