77use  Illuminate \Contracts \Support \Arrayable ;
88use  Illuminate \Contracts \Support \Responsable ;
99use  Illuminate \Http \JsonResponse ;
10+ use  Illuminate \Http \Request ;
1011use  Illuminate \Http \Resources \Json \JsonResource ;
1112use  Illuminate \Http \Resources \Json \ResourceResponse ;
1213use  Illuminate \Support \Arr ;
@@ -93,34 +94,7 @@ public function toResponse($request)
9394                return  ! ($ propinstanceof  LazyProp);
9495            });
9596
96-         array_walk_recursive ($ propsstatic  function  (&$ propuse  ($ request
97-             if  ($ propinstanceof  LazyProp) {
98-                 $ propcall ($ prop
99-             }
100- 
101-             if  ($ propinstanceof  Closure) {
102-                 $ propcall ($ prop
103-             }
104- 
105-             if  ($ propinstanceof  PromiseInterface) {
106-                 $ prop$ propwait ();
107-             }
108- 
109-             if  ($ propinstanceof  ResourceResponse || $ propinstanceof  JsonResource) {
110-                 $ prop$ proptoResponse ($ requestgetData (true );
111-             }
112- 
113-             if  ($ propinstanceof  Arrayable) {
114-                 $ prop$ proptoArray ();
115-             }
116-         });
117- 
118-         foreach  ($ propsas  $ key$ value
119-             if  (str_contains ($ key'. ' )) {
120-                 data_set ($ props$ key$ value
121-                 unset($ props$ key
122-             }
123-         }
97+         $ props$ this resolvePropertyInstances ($ props$ request
12498
12599        $ page
126100            'component '  => $ this component ,
@@ -138,4 +112,44 @@ public function toResponse($request)
138112
139113        return  ResponseFactory::view ($ this rootView , $ this viewData  + ['page '  => $ page
140114    }
115+ 
116+     /** 
117+      * Resolve all necessary class instances in the given props. 
118+      * 
119+      * @param  array  $props 
120+      * @param  \Illuminate\Http\Request  $request 
121+      * @return array 
122+      */ 
123+     public  function  resolvePropertyInstances (array  $ propsRequest $ requestarray 
124+     {
125+         foreach  ($ propsas  $ key$ value
126+             if  ($ valueinstanceof  Closure) {
127+                 $ valuecall ($ value
128+             }
129+ 
130+             if  ($ valueinstanceof  LazyProp) {
131+                 $ valuecall ($ value
132+             }
133+ 
134+             if  ($ valueinstanceof  PromiseInterface) {
135+                 $ value$ valuewait ();
136+             }
137+ 
138+             if  ($ valueinstanceof  ResourceResponse || $ valueinstanceof  JsonResource) {
139+                 $ value$ valuetoResponse ($ requestgetData (true );
140+             }
141+ 
142+             if  ($ valueinstanceof  Arrayable) {
143+                 $ value$ valuetoArray ();
144+             }
145+ 
146+             if  (is_array ($ value
147+                 $ value$ this resolvePropertyInstances ($ value$ request
148+             }
149+ 
150+             Arr::set ($ props$ key$ value
151+         }
152+ 
153+         return  $ props
154+     }
141155}
0 commit comments