File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff 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 ();
Original file line number Diff line number Diff line change 22
33namespace Inertia \Tests ;
44
5+ use Illuminate \Contracts \Support \Arrayable ;
56use Illuminate \Http \RedirectResponse ;
67use Illuminate \Http \Response ;
78use 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}
You can’t perform that action at this time.
0 commit comments