Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public function lazy(callable $callback): LazyProp
return new LazyProp($callback);
}

public function render($component, array $props = []): Response
/**
* @param string $component
* @param array|Arrayable $props
*/
public function render($component, $props = []): Response
{
if ($props instanceof Arrayable) {
$props = $props->toArray();
Expand Down
27 changes: 27 additions & 0 deletions tests/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Inertia\Tests;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Illuminate\Session\Middleware\StartSession;
Expand Down Expand Up @@ -131,4 +132,30 @@ public function test_can_create_lazy_prop(): void

$this->assertInstanceOf(LazyProp::class, $lazyProp);
}

public function test_will_accept_arrayabe_props()
{
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
Inertia::share('foo', 'bar');

return Inertia::render('User/Edit', new class implements Arrayable
{
public function toArray()
{
return [
'foo' => 'bar',
];
}
});
});

$response = $this->withoutExceptionHandling()->get('/', ['X-Inertia' => 'true']);
$response->assertSuccessful();
$response->assertJson([
'component' => 'User/Edit',
'props' => [
'foo' => 'bar',
],
]);
}
}