@@ -82,16 +82,21 @@ protected function buildMethods(Controller $controller): string
82
82
83
83
foreach ($ controller ->methods () as $ name => $ statements ) {
84
84
$ method = str_replace ('{{ method }} ' , $ name , $ template );
85
+ $ search = '(Request $request ' ;
85
86
86
87
if (in_array ($ name , ['edit ' , 'update ' , 'show ' , 'destroy ' ])) {
87
88
$ reference = $ this ->fullyQualifyModelReference ($ controller ->namespace (), $ controllerModelName );
88
89
$ variable = '$ ' . Str::camel ($ controllerModelName );
89
90
90
- $ search = '(Request $request ' ;
91
91
$ method = str_replace ($ search , $ search . ', ' . $ controllerModelName . ' ' . $ variable , $ method );
92
92
$ this ->addImport ($ controller , $ reference );
93
93
}
94
94
95
+ if ($ parent = $ controller ->parent ()) {
96
+ $ method = str_replace ($ search , $ search . ', ' . $ parent . ' $ ' . Str::camel ($ parent ), $ method );
97
+ $ this ->addImport ($ controller , $ this ->fullyQualifyModelReference ($ controller ->namespace (), $ parent ));
98
+ }
99
+
95
100
$ body = '' ;
96
101
$ using_validation = false ;
97
102
@@ -181,6 +186,17 @@ protected function buildMethods(Controller $controller): string
181
186
$ this ->addImport ($ controller , 'Inertia\Inertia ' );
182
187
}
183
188
189
+ if (
190
+ $ controller ->parent () &&
191
+ ($ statement instanceof QueryStatement || $ statement instanceof EloquentStatement || $ statement instanceof ResourceStatement)
192
+ ) {
193
+ $ body = str_replace (
194
+ ['::all ' , Str::singular ($ controller ->prefix ()) . ':: ' ],
195
+ ['::get ' , '$ ' . Str::lower ($ controller ->parent ()) . '-> ' . Str::plural (Str::lower ($ controller ->prefix ())) . '()-> ' ],
196
+ $ body
197
+ );
198
+ }
199
+
184
200
$ body .= PHP_EOL ;
185
201
}
186
202
0 commit comments