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
85
85
return new LazyProp ($ callback );
86
86
}
87
87
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
89
93
{
90
94
if ($ props instanceof Arrayable) {
91
95
$ props = $ props ->toArray ();
Original file line number Diff line number Diff line change 2
2
3
3
namespace Inertia \Tests ;
4
4
5
+ use Illuminate \Contracts \Support \Arrayable ;
5
6
use Illuminate \Http \RedirectResponse ;
6
7
use Illuminate \Http \Response ;
7
8
use Illuminate \Session \Middleware \StartSession ;
@@ -131,4 +132,30 @@ public function test_can_create_lazy_prop(): void
131
132
132
133
$ this ->assertInstanceOf (LazyProp::class, $ lazyProp );
133
134
}
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
+ }
134
161
}
You can’t perform that action at this time.
0 commit comments