44
55use App \Http \Controllers \Controller ;
66use Illuminate \Http \Request ;
7+ use Illuminate \Support \Str ;
78use Nette \PhpGenerator \ClassType ;
89use Nette \PhpGenerator \PhpNamespace ;
910use Shetabit \ModuleGenerator \Helpers \Helper ;
@@ -27,10 +28,7 @@ class ControllerGenerator
2728 */
2829 protected $ baseRelationName ;
2930 protected $ attributes ;
30- <<<<<<< HEAD
31- =======
3231 protected $ config ;
33- >>>>>>> 73 a07f9... first commit
3432
3533 public function __construct ($ module , $ models )
3634 {
@@ -80,18 +78,6 @@ public function generateControllerTemplates($option): PhpNamespace
8078
8179 public function setMethodToController ($ class , $ option , $ namespace )
8280 {
83- <<<<<<< HEAD
84- if (strpos ($ option , 'R ' ) == true ) {
85- $ this ->indexAndShowMethodGenerator ($ class );
86- }
87- if (strpos ($ option , 'C ' ) == true ) {
88- $ this ->createAndStoreMethodGenerator ($ class );
89- }
90- if (strpos ($ option , 'U ' ) == true ) {
91- $ this ->editAndUpdateMethodGenerator ($ class , $ namespace );
92- }
93- if (strpos ($ option , 'D ' ) == true ) {
94- =======
9581 if (str_contains ($ option , 'R ' )) {
9682 $ this ->indexAndShowMethodGenerator ($ class );
9783 }
@@ -102,7 +88,6 @@ public function setMethodToController($class, $option, $namespace)
10288 $ this ->editAndUpdateMethodGenerator ($ class , $ namespace );
10389 }
10490 if (str_contains ($ option , 'D ' )) {
105- >>>>>>> 73 a07f9.. . first commit
10691 $ this ->destroyMethodGenerator ($ class );
10792 }
10893 }
@@ -112,16 +97,6 @@ public function indexAndShowMethodGenerator(classType $class)
11297 $ method = $ class ->addMethod ('index ' );
11398 if (key_exists ('Relations ' , $ this ->attributes )) {
11499 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . 's = ' . ucfirst ($ this ->modelName ) . '::withCommonRelations()->get(); ' . PHP_EOL )
115- <<<<<<< HEAD
116- ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . 's); ' );
117- } else {
118- $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . 's = ' . ucfirst ($ this ->modelName ) . '::query()->get(); ' . PHP_EOL )
119- ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . 's); ' );
120- }
121- $ class ->addMethod ('show ' )
122- ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' . PHP_EOL )
123- ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . '); ' )
124- =======
125100 ->addBody ($ this ->config ['return ' ]);
126101 } else {
127102 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . 's = ' . ucfirst ($ this ->modelName ) . '::query()->get(); ' . PHP_EOL )
@@ -130,7 +105,6 @@ public function indexAndShowMethodGenerator(classType $class)
130105 $ class ->addMethod ('show ' )
131106 ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' . PHP_EOL )
132107 ->addBody ($ this ->config ['return ' ])
133- >>>>>>> 73 a07f9.. . first commit
134108 ->addParameter ('id ' )->setType ('Int ' );
135109 }
136110
@@ -159,12 +133,9 @@ public function associateInStore($method)
159133 {
160134 if (key_exists ('Relations ' , $ this ->attributes )) {
161135 foreach ($ this ->attributes ['Relations ' ] as $ typeRelation => $ relations ) {
162- <<<<<<< HEAD
163- =======
164136 if (!is_array ($ relations ) && Str::camel ($ relations ) == 'morphTo ' ){
165137 return '' ;
166138 }
167- >>>>>>> 73 a07f9.. . first commit
168139 foreach ($ relations as $ value ) {
169140 $ this ->baseRelationName = explode (':: ' , $ value )[1 ];
170141 $ this ->relationName = Helper::configurationRelationsName ($ this ->baseRelationName , $ typeRelation );
@@ -174,36 +145,23 @@ public function associateInStore($method)
174145 }
175146 }
176147
177- <<<<<<< HEAD
178- public function editAndUpdateMethodGenerator(ClassType $ class , $ namespace )
179- =======
148+
180149 public function editAndUpdateMethodGenerator (ClassType $ class , $ namespace )
181- >>>>>>> 73 a07f9... first commit
182150 {
183151 $ method = $ class ->addMethod ('edit ' );
184152 if (key_exists ('Relations ' , $ this ->attributes )) {
185153 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::withCommonRelations()->findOrFail($id); ' . PHP_EOL )
186- <<<<<<< HEAD
187- ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . '); ' );
188- } else {
189- $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' . PHP_EOL )
190- ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . '); ' );
191- =======
192154 ->addBody ($ this ->config ['return ' ]);
193155 } else {
194156 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' . PHP_EOL )
195157 ->addBody ($ this ->config ['return ' ]);
196- >>>>>>> 73 a07f9.. . first commit
197158 };
198159 $ method ->addParameter ('id ' )->setType ('Int ' );
199160
200161 $ method = $ class ->addMethod ('update ' )
201162 ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' );
202- <<<<<<< HEAD
203- $ this ->UpdateMethodFindIntoRelation ($ method , $ namespace );
204- =======
163+
205164 $ this ->UpdateMethodFindIntoRelation ($ method , $ namespace );
206- >>>>>>> 73 a07f9.. . first commit
207165 $ this ->associateInUpdate ($ method );
208166 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . '->fill($request->all()); ' )
209167 ->addBody ('$ ' . strtolower ($ this ->modelName ) . '->save(); ' .PHP_EOL )
@@ -215,20 +173,14 @@ public function editAndUpdateMethodGenerator(ClassType $class , $namespace)
215173 $ method ->addParameter ('id ' )->setType ('Int ' );
216174 }
217175
218- <<<<<<< HEAD
219- public function UpdateMethodFindIntoRelation($ method , $ namespace )
220- {
221- if (key_exists ('Relations ' , $ this ->attributes )) {
222- foreach ($ this ->attributes ['Relations ' ] as $ typeRelation => $ relations ) {
223- =======
176+
224177 public function UpdateMethodFindIntoRelation ($ method ,$ namespace )
225178 {
226179 if (key_exists ('Relations ' , $ this ->attributes )) {
227180 foreach ($ this ->attributes ['Relations ' ] as $ typeRelation => $ relations ) {
228181 if (!is_array ($ relations ) && Str::camel ($ relations ) == 'morphTo ' ){
229182 return '' ;
230183 }
231- >>>>>>> 73 a07f9.. . first commit
232184 foreach ($ relations as $ value ) {
233185 $ this ->baseRelationName = explode (':: ' , $ value )[1 ];
234186 $ method ->addBody ('$ ' . strtolower ($ this ->baseRelationName ) . ' = ' . ucfirst ($ this ->baseRelationName ) . '::query()->findOrFail($request-> ' . strtolower ($ this ->baseRelationName ) . '_id); ' );
@@ -242,12 +194,9 @@ public function associateInUpdate($method)
242194 {
243195 if (key_exists ('Relations ' , $ this ->attributes )) {
244196 foreach ($ this ->attributes ['Relations ' ] as $ typeRelation => $ relations ) {
245- <<<<<<< HEAD
246- =======
247197 if (!is_array ($ relations ) && Str::camel ($ relations ) == 'morphTo ' ){
248198 return '' ;
249199 }
250- >>>>>>> 73 a07f9.. . first commit
251200 foreach ($ relations as $ value ) {
252201 $ this ->baseRelationName = explode (':: ' , $ value )[1 ];
253202 $ this ->relationName = Helper::configurationRelationsName ($ this ->baseRelationName , $ typeRelation );
@@ -261,11 +210,7 @@ public function destroyMethodGenerator(ClassType $class)
261210 {
262211 $ class ->addMethod ('destroy ' )
263212 ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::destroy($id); ' . PHP_EOL )
264- <<<<<<< HEAD
265- ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . '); ' )
266- =======
267213 ->addBody ($ this ->config ['return ' ])
268- >>>>>>> 73 a07f9.. . first commit
269214 ->addParameter ('id ' )->setType ('Int ' );
270215 }
271216
0 commit comments