@@ -125,7 +125,7 @@ public function deleteService(Request $request, $service)
125125 return redirect ()->route ('admin.services.service ' , $ service );
126126 }
127127
128- public function getOption (Request $ request , $ option )
128+ public function getOption (Request $ request , $ service , $ option )
129129 {
130130 $ opt = Models \ServiceOptions::findOrFail ($ option );
131131 return view ('admin.services.options.view ' , [
@@ -139,7 +139,7 @@ public function getOption(Request $request, $option)
139139 ]);
140140 }
141141
142- public function postOption (Request $ request , $ option )
142+ public function postOption (Request $ request , $ service , $ option )
143143 {
144144 try {
145145 $ repo = new ServiceRepository \Option ;
@@ -148,15 +148,15 @@ public function postOption(Request $request, $option)
148148 ]));
149149 Alert::success ('Option settings successfully updated. ' )->flash ();
150150 } catch (DisplayValidationException $ ex ) {
151- return redirect ()->route ('admin.services.option ' , $ option )->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
151+ return redirect ()->route ('admin.services.option ' , [ $ service , $ option] )->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
152152 } catch (\Exception $ ex ) {
153153 Log::error ($ ex );
154154 Alert::danger ('An error occured while attempting to modify this option. ' )->flash ();
155155 }
156- return redirect ()->route ('admin.services.option ' , $ option )->withInput ();
156+ return redirect ()->route ('admin.services.option ' , [ $ service , $ option] )->withInput ();
157157 }
158158
159- public function deleteOption (Request $ request , $ option )
159+ public function deleteOption (Request $ request , $ service , $ option )
160160 {
161161 try {
162162 $ service = Models \ServiceOptions::select ('parent_service ' )->where ('id ' , $ option )->first ();
@@ -171,39 +171,35 @@ public function deleteOption(Request $request, $option)
171171 Log::error ($ ex );
172172 Alert::danger ('An error was encountered while attempting to delete this option. ' )->flash ();
173173 }
174- return redirect ()->route ('admin.services.option ' , $ option );
174+ return redirect ()->route ('admin.services.option ' , [ $ service , $ option] );
175175 }
176176
177- public function postOptionVariable (Request $ request , $ option , $ variable )
177+ public function postOptionVariable (Request $ request , $ service , $ option , $ variable )
178178 {
179- if ($ variable === 'new ' ) {
180- // adding new variable
181- } else {
182- try {
183- $ repo = new ServiceRepository \Variable ;
184-
185- // Because of the way old() works on the display side we prefix all of the variables with thier ID
186- // We need to remove that prefix here since the repo doesn't want it.
187- $ data = [];
188- foreach ($ request ->except (['_token ' ]) as $ id => $ val ) {
189- $ data [str_replace ($ variable .'_ ' , '' , $ id )] = $ val ;
190- }
191- $ repo ->update ($ variable , $ data );
192- Alert::success ('Successfully updated variable. ' )->flash ();
193- } catch (DisplayValidationException $ ex ) {
194- $ data = [];
195- foreach (json_decode ($ ex ->getMessage (), true ) as $ id => $ val ) {
196- $ data [$ variable .'_ ' .$ id ] = $ val ;
197- }
198- return redirect ()->route ('admin.services.option ' , $ option )->withErrors ((object ) $ data )->withInput ();
199- } catch (DisplayException $ ex ) {
200- Alert::danger ($ ex ->getMessage ())->flash ();
201- } catch (\Exception $ ex ) {
202- Log::error ($ ex );
203- Alert::danger ('An error occurred while attempting to update this service. ' )->flash ();
179+ try {
180+ $ repo = new ServiceRepository \Variable ;
181+
182+ // Because of the way old() works on the display side we prefix all of the variables with thier ID
183+ // We need to remove that prefix here since the repo doesn't want it.
184+ $ data = [];
185+ foreach ($ request ->except (['_token ' ]) as $ id => $ val ) {
186+ $ data [str_replace ($ variable .'_ ' , '' , $ id )] = $ val ;
204187 }
205- return redirect ()->route ('admin.services.option ' , $ option )->withInput ();
188+ $ repo ->update ($ variable , $ data );
189+ Alert::success ('Successfully updated variable. ' )->flash ();
190+ } catch (DisplayValidationException $ ex ) {
191+ $ data = [];
192+ foreach (json_decode ($ ex ->getMessage (), true ) as $ id => $ val ) {
193+ $ data [$ variable .'_ ' .$ id ] = $ val ;
194+ }
195+ return redirect ()->route ('admin.services.option ' , [$ service , $ option ])->withErrors ((object ) $ data )->withInput ();
196+ } catch (DisplayException $ ex ) {
197+ Alert::danger ($ ex ->getMessage ())->flash ();
198+ } catch (\Exception $ ex ) {
199+ Log::error ($ ex );
200+ Alert::danger ('An error occurred while attempting to update this service. ' )->flash ();
206201 }
202+ return redirect ()->route ('admin.services.option ' , [$ service , $ option ])->withInput ();
207203 }
208204
209205 public function newOption (Request $ request , $ service )
@@ -221,7 +217,7 @@ public function postNewOption(Request $request, $service)
221217 '_token '
222218 ]));
223219 Alert::success ('Successfully created new service option. ' )->flash ();
224- return redirect ()->route ('admin.services.option ' , $ id );
220+ return redirect ()->route ('admin.services.option ' , [ $ service , $ id ] );
225221 } catch (DisplayValidationException $ ex ) {
226222 return redirect ()->route ('admin.services.option.new ' , $ service )->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
227223 } catch (\Exception $ ex ) {
0 commit comments