File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Inertia ;
4
+
5
+ use Illuminate \Support \Facades \App ;
6
+
7
+ class LazyProp
8
+ {
9
+ protected $ callback ;
10
+
11
+ public function __construct (callable $ callback )
12
+ {
13
+ $ this ->callback = $ callback ;
14
+ }
15
+
16
+ public function __invoke ()
17
+ {
18
+ return App::call ($ this ->callback );
19
+ }
20
+ }
Original file line number Diff line number Diff line change @@ -54,9 +54,15 @@ public function toResponse($request)
54
54
55
55
$ props = ($ only && $ request ->header ('X-Inertia-Partial-Component ' ) === $ this ->component )
56
56
? Arr::only ($ this ->props , $ only )
57
- : $ this ->props ;
57
+ : array_filter ($ this ->props , function ($ prop ) {
58
+ return ! ($ prop instanceof LazyProp);
59
+ });
58
60
59
61
array_walk_recursive ($ props , function (&$ prop ) use ($ request ) {
62
+ if ($ prop instanceof LazyProp) {
63
+ $ prop = App::call ($ prop );
64
+ }
65
+
60
66
if ($ prop instanceof Closure) {
61
67
$ prop = App::call ($ prop );
62
68
}
Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ public function getVersion()
54
54
return (string ) $ version ;
55
55
}
56
56
57
+ public function lazy (callable $ callback )
58
+ {
59
+ return new LazyProp ($ callback );
60
+ }
61
+
57
62
public function render ($ component , $ props = [])
58
63
{
59
64
if ($ props instanceof Arrayable) {
You can’t perform that action at this time.
0 commit comments