@@ -69,7 +69,19 @@ private function buildMethods(Controller $controller)
69
69
foreach ($ controller ->methods () as $ name => $ statements ) {
70
70
$ method = str_replace ('DummyMethod ' , $ name , $ template );
71
71
72
- // TODO: if resourceful action, do implicit model binding
72
+ if (in_array ($ name , ['edit ' , 'update ' , 'show ' , 'destroy ' ])) {
73
+ $ context = Str::singular ($ controller ->prefix ());
74
+ $ reference = 'App \\' . $ context ;
75
+ $ variable = '$ ' . Str::camel ($ context );
76
+
77
+ // TODO: verify is model
78
+ $ search = ' * @return \\Illuminate \\Http \\Response ' ;
79
+ $ method = str_replace ($ search ,' * @param \\' . $ reference . ' ' . $ variable . PHP_EOL . $ search , $ method );
80
+
81
+ $ search = '(Request $request ' ;
82
+ $ method = str_replace ($ search , $ search . ', ' . $ context . ' ' . $ variable , $ method );
83
+ $ this ->addImport ($ controller , $ reference );
84
+ }
73
85
74
86
$ body = '' ;
75
87
foreach ($ statements as $ statement ) {
@@ -81,7 +93,7 @@ private function buildMethods(Controller $controller)
81
93
$ class = $ controller ->name () . Str::studly ($ name ) . 'Request ' ;
82
94
83
95
$ method = str_replace ('\Illuminate\Http\Request $request ' , '\\App \\Http \\Requests \\' . $ class . ' $request ' , $ method );
84
- $ method = str_replace ('(Request $request) ' , '( ' . $ class . ' $request) ' , $ method );
96
+ $ method = str_replace ('(Request $request ' , '( ' . $ class . ' $request ' , $ method );
85
97
86
98
$ this ->addImport ($ controller , 'App \\Http \\Requests \\' . $ class );
87
99
} elseif ($ statement instanceof DispatchStatement) {
@@ -100,7 +112,7 @@ private function buildMethods(Controller $controller)
100
112
$ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
101
113
} elseif ($ statement instanceof EloquentStatement) {
102
114
// TODO: pass controller method for context..
103
- $ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
115
+ $ body .= self ::INDENT . $ statement ->output ($ name ) . PHP_EOL ;
104
116
$ this ->addImport ($ controller , 'App \\' . Str::studly ($ statement ->reference ()));
105
117
} elseif ($ statement instanceof QueryStatement) {
106
118
$ body .= self ::INDENT . $ statement ->output () . PHP_EOL ;
0 commit comments