@@ -27,11 +27,17 @@ class ControllerGenerator
2727 */
2828 protected $ baseRelationName ;
2929 protected $ attributes ;
30+ <<<<<<< HEAD
31+ =======
32+ protected $ config ;
33+ >>>>>>> 73 a07f9... first commit
3034
3135 public function __construct ($ module , $ models )
3236 {
3337 $ this ->models = $ models ['Models ' ];
3438 $ this ->module = $ module ;
39+ $ this ->config = \config ()->get ('moduleConfig ' );
40+
3541 }
3642
3743 public function generate (): string
@@ -74,6 +80,7 @@ public function generateControllerTemplates($option): PhpNamespace
7480
7581 public function setMethodToController ($ class , $ option , $ namespace )
7682 {
83+ <<<<<<< HEAD
7784 if (strpos ($ option , 'R ' ) == true ) {
7885 $ this ->indexAndShowMethodGenerator ($ class );
7986 }
@@ -84,6 +91,18 @@ public function setMethodToController($class, $option, $namespace)
8491 $ this ->editAndUpdateMethodGenerator ($ class , $ namespace );
8592 }
8693 if (strpos ($ option , 'D ' ) == true ) {
94+ =======
95+ if (str_contains ($ option , 'R ' )) {
96+ $ this ->indexAndShowMethodGenerator ($ class );
97+ }
98+ if (str_contains ($ option , 'C ' )) {
99+ $ this ->createAndStoreMethodGenerator ($ class );
100+ }
101+ if (str_contains ($ option , 'U ' )) {
102+ $ this ->editAndUpdateMethodGenerator ($ class , $ namespace );
103+ }
104+ if (str_contains ($ option , 'D ' )) {
105+ >>>>>>> 73 a07f9.. . first commit
87106 $ this ->destroyMethodGenerator ($ class );
88107 }
89108 }
@@ -93,6 +112,7 @@ public function indexAndShowMethodGenerator(classType $class)
93112 $ method = $ class ->addMethod ('index ' );
94113 if (key_exists ('Relations ' , $ this ->attributes )) {
95114 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . 's = ' . ucfirst ($ this ->modelName ) . '::withCommonRelations()->get(); ' . PHP_EOL )
115+ <<<<<<< HEAD
96116 ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . 's); ' );
97117 } else {
98118 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . 's = ' . ucfirst ($ this ->modelName ) . '::query()->get(); ' . PHP_EOL )
@@ -101,6 +121,16 @@ public function indexAndShowMethodGenerator(classType $class)
101121 $ class ->addMethod ('show ' )
102122 ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' . PHP_EOL )
103123 ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . '); ' )
124+ =======
125+ ->addBody ($ this ->config ['return ' ]);
126+ } else {
127+ $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . 's = ' . ucfirst ($ this ->modelName ) . '::query()->get(); ' . PHP_EOL )
128+ ->addBody ($ this ->config ['return ' ]);
129+ }
130+ $ class ->addMethod ('show ' )
131+ ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' . PHP_EOL )
132+ ->addBody ($ this ->config ['return ' ])
133+ >>>>>>> 73 a07f9.. . first commit
104134 ->addParameter ('id ' )->setType ('Int ' );
105135 }
106136
@@ -129,6 +159,12 @@ public function associateInStore($method)
129159 {
130160 if (key_exists ('Relations ' , $ this ->attributes )) {
131161 foreach ($ this ->attributes ['Relations ' ] as $ typeRelation => $ relations ) {
162+ <<<<<<< HEAD
163+ =======
164+ if (!is_array ($ relations ) && Str::camel ($ relations ) == 'morphTo ' ){
165+ return '' ;
166+ }
167+ >>>>>>> 73 a07f9.. . first commit
132168 foreach ($ relations as $ value ) {
133169 $ this ->baseRelationName = explode (':: ' , $ value )[1 ];
134170 $ this ->relationName = Helper::configurationRelationsName ($ this ->baseRelationName , $ typeRelation );
@@ -138,21 +174,36 @@ public function associateInStore($method)
138174 }
139175 }
140176
177+ <<<<<<< HEAD
141178 public function editAndUpdateMethodGenerator(ClassType $ class , $ namespace )
179+ =======
180+ public function editAndUpdateMethodGenerator(ClassType $ class , $ namespace )
181+ >>>>>>> 73 a07f9... first commit
142182 {
143183 $ method = $ class ->addMethod ('edit ' );
144184 if (key_exists ('Relations ' , $ this ->attributes )) {
145185 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::withCommonRelations()->findOrFail($id); ' . PHP_EOL )
186+ <<<<<<< HEAD
146187 ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . '); ' );
147188 } else {
148189 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' . PHP_EOL )
149190 ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . '); ' );
191+ =======
192+ ->addBody ($ this ->config ['return ' ]);
193+ } else {
194+ $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' . PHP_EOL )
195+ ->addBody ($ this ->config ['return ' ]);
196+ >>>>>>> 73 a07f9.. . first commit
150197 };
151198 $ method ->addParameter ('id ' )->setType ('Int ' );
152199
153200 $ method = $ class ->addMethod ('update ' )
154201 ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::query()->findOrFail($id); ' );
202+ <<<<<<< HEAD
155203 $ this ->UpdateMethodFindIntoRelation ($ method , $ namespace );
204+ =======
205+ $ this ->UpdateMethodFindIntoRelation ($ method , $ namespace );
206+ >>>>>>> 73 a07f9.. . first commit
156207 $ this ->associateInUpdate ($ method );
157208 $ method ->addBody ('$ ' . strtolower ($ this ->modelName ) . '->fill($request->all()); ' )
158209 ->addBody ('$ ' . strtolower ($ this ->modelName ) . '->save(); ' .PHP_EOL )
@@ -164,10 +215,20 @@ public function editAndUpdateMethodGenerator(ClassType $class, $namespace)
164215 $ method ->addParameter ('id ' )->setType ('Int ' );
165216 }
166217
218+ <<<<<<< HEAD
167219 public function UpdateMethodFindIntoRelation($ method , $ namespace )
168220 {
169221 if (key_exists ('Relations ' , $ this ->attributes )) {
170222 foreach ($ this ->attributes ['Relations ' ] as $ typeRelation => $ relations ) {
223+ =======
224+ public function UpdateMethodFindIntoRelation ($ method ,$ namespace )
225+ {
226+ if (key_exists ('Relations ' , $ this ->attributes )) {
227+ foreach ($ this ->attributes ['Relations ' ] as $ typeRelation => $ relations ) {
228+ if (!is_array ($ relations ) && Str::camel ($ relations ) == 'morphTo ' ){
229+ return '' ;
230+ }
231+ >>>>>>> 73 a07f9.. . first commit
171232 foreach ($ relations as $ value ) {
172233 $ this ->baseRelationName = explode (':: ' , $ value )[1 ];
173234 $ method ->addBody ('$ ' . strtolower ($ this ->baseRelationName ) . ' = ' . ucfirst ($ this ->baseRelationName ) . '::query()->findOrFail($request-> ' . strtolower ($ this ->baseRelationName ) . '_id); ' );
@@ -181,6 +242,12 @@ public function associateInUpdate($method)
181242 {
182243 if (key_exists ('Relations ' , $ this ->attributes )) {
183244 foreach ($ this ->attributes ['Relations ' ] as $ typeRelation => $ relations ) {
245+ <<<<<<< HEAD
246+ =======
247+ if (!is_array ($ relations ) && Str::camel ($ relations ) == 'morphTo ' ){
248+ return '' ;
249+ }
250+ >>>>>>> 73 a07f9.. . first commit
184251 foreach ($ relations as $ value ) {
185252 $ this ->baseRelationName = explode (':: ' , $ value )[1 ];
186253 $ this ->relationName = Helper::configurationRelationsName ($ this ->baseRelationName , $ typeRelation );
@@ -194,7 +261,11 @@ public function destroyMethodGenerator(ClassType $class)
194261 {
195262 $ class ->addMethod ('destroy ' )
196263 ->addBody ('$ ' . strtolower ($ this ->modelName ) . ' = ' . ucfirst ($ this ->modelName ) . '::destroy($id); ' . PHP_EOL )
264+ <<<<<<< HEAD
197265 ->addBody ('return response()->json($ ' . strtolower ($ this ->modelName ) . '); ' )
266+ =======
267+ ->addBody ($ this ->config ['return ' ])
268+ >>>>>>> 73 a07f9.. . first commit
198269 ->addParameter ('id ' )->setType ('Int ' );
199270 }
200271
0 commit comments