@@ -45,10 +45,7 @@ public function __construct()
4545 public function getIndex (Request $ request )
4646 {
4747 return view ('admin.services.index ' , [
48- 'services ' => Models \Service::select (
49- 'services.* ' ,
50- DB ::raw ('(SELECT COUNT(*) FROM servers WHERE servers.service = services.id) as c_servers ' )
51- )->get (),
48+ 'services ' => Models \Service::withCount ('servers ' )->get (),
5249 ]);
5350 }
5451
@@ -61,12 +58,16 @@ public function postNew(Request $request)
6158 {
6259 try {
6360 $ repo = new ServiceRepository \Service ;
64- $ id = $ repo ->create ($ request ->except ([
65- '_token ' ,
61+ $ service = $ repo ->create ($ request ->only ([
62+ 'name ' ,
63+ 'description ' ,
64+ 'file ' ,
65+ 'executable ' ,
66+ 'startup ' ,
6667 ]));
6768 Alert::success ('Successfully created new service! ' )->flash ();
6869
69- return redirect ()->route ('admin.services.service ' , $ id );
70+ return redirect ()->route ('admin.services.service ' , $ service -> id );
7071 } catch (DisplayValidationException $ ex ) {
7172 return redirect ()->route ('admin.services.new ' )->withErrors (json_decode ($ ex ->getMessage ()))->withInput ();
7273 } catch (DisplayException $ ex ) {
@@ -82,20 +83,20 @@ public function postNew(Request $request)
8283 public function getService (Request $ request , $ service )
8384 {
8485 return view ('admin.services.view ' , [
85- 'service ' => Models \Service::findOrFail ($ service ),
86- 'options ' => Models \ServiceOptions::select (
87- 'service_options.* ' ,
88- DB ::raw ('(SELECT COUNT(*) FROM servers WHERE servers.option = service_options.id) as c_servers ' )
89- )->where ('parent_service ' , $ service )->get (),
86+ 'service ' => Models \Service::with ('options ' , 'options.servers ' )->findOrFail ($ service ),
9087 ]);
9188 }
9289
9390 public function postService (Request $ request , $ service )
9491 {
9592 try {
9693 $ repo = new ServiceRepository \Service ;
97- $ repo ->update ($ service , $ request ->except ([
98- '_token ' ,
94+ $ repo ->update ($ service , $ request ->only ([
95+ 'name ' ,
96+ 'description ' ,
97+ 'file ' ,
98+ 'executable ' ,
99+ 'startup ' ,
99100 ]));
100101 Alert::success ('Successfully updated this service. ' )->flash ();
101102 } catch (DisplayValidationException $ ex ) {
@@ -130,25 +131,25 @@ public function deleteService(Request $request, $service)
130131
131132 public function getOption (Request $ request , $ service , $ option )
132133 {
133- $ opt = Models \ServiceOptions::findOrFail ($ option );
134+ $ option = Models \ServiceOptions::with ('service ' , 'variables ' )->findOrFail ($ option );
135+ $ option ->setRelation ('servers ' , $ option ->servers ()->with ('user ' )->paginate (25 ));
134136
135137 return view ('admin.services.options.view ' , [
136- 'service ' => Models \Service::findOrFail ($ opt ->parent_service ),
137- 'option ' => $ opt ,
138- 'variables ' => Models \ServiceVariables::where ('option_id ' , $ option )->get (),
139- 'servers ' => Models \Server::select ('servers.* ' , 'users.email as a_ownerEmail ' )
140- ->join ('users ' , 'users.id ' , '= ' , 'servers.owner_id ' )
141- ->where ('option ' , $ option )
142- ->paginate (10 ),
138+ 'option ' => $ option ,
143139 ]);
144140 }
145141
146142 public function postOption (Request $ request , $ service , $ option )
147143 {
148144 try {
149145 $ repo = new ServiceRepository \Option ;
150- $ repo ->update ($ option , $ request ->except ([
151- '_token ' ,
146+ $ repo ->update ($ option , $ request ->only ([
147+ 'name ' ,
148+ 'description ' ,
149+ 'tag ' ,
150+ 'executable ' ,
151+ 'docker_image ' ,
152+ 'startup ' ,
152153 ]));
153154 Alert::success ('Option settings successfully updated. ' )->flash ();
154155 } catch (DisplayValidationException $ ex ) {
@@ -164,13 +165,12 @@ public function postOption(Request $request, $service, $option)
164165 public function deleteOption (Request $ request , $ service , $ option )
165166 {
166167 try {
167- $ service = Models \ServiceOptions::select ('parent_service ' )->where ('id ' , $ option )->first ();
168168 $ repo = new ServiceRepository \Option ;
169169 $ repo ->delete ($ option );
170170
171171 Alert::success ('Successfully deleted that option. ' )->flash ();
172172
173- return redirect ()->route ('admin.services.service ' , $ service-> parent_service );
173+ return redirect ()->route ('admin.services.service ' , $ service );
174174 } catch (DisplayException $ ex ) {
175175 Alert::danger ($ ex ->getMessage ())->flash ();
176176 } catch (\Exception $ ex ) {
@@ -218,17 +218,23 @@ public function postOptionVariable(Request $request, $service, $option, $variabl
218218 public function getNewVariable (Request $ request , $ service , $ option )
219219 {
220220 return view ('admin.services.options.variable ' , [
221- 'service ' => Models \Service::findOrFail ($ service ),
222- 'option ' => Models \ServiceOptions::where ('parent_service ' , $ service )->where ('id ' , $ option )->firstOrFail (),
221+ 'option ' => Models \ServiceOptions::with ('service ' )->findOrFail ($ option ),
223222 ]);
224223 }
225224
226225 public function postNewVariable (Request $ request , $ service , $ option )
227226 {
228227 try {
229228 $ repo = new ServiceRepository \Variable ;
230- $ repo ->create ($ option , $ request ->except ([
231- '_token ' ,
229+ $ repo ->create ($ option , $ request ->only ([
230+ 'name ' ,
231+ 'description ' ,
232+ 'env_variable ' ,
233+ 'default_value ' ,
234+ 'user_viewable ' ,
235+ 'user_editable ' ,
236+ 'required ' ,
237+ 'regex ' ,
232238 ]));
233239 Alert::success ('Successfully added new variable to this option. ' )->flash ();
234240
@@ -305,8 +311,9 @@ public function postConfiguration(Request $request, $serviceId)
305311 {
306312 try {
307313 $ repo = new ServiceRepository \Service ;
308- $ repo ->updateFile ($ serviceId , $ request ->except ([
309- '_token ' ,
314+ $ repo ->updateFile ($ serviceId , $ request ->only ([
315+ 'file ' ,
316+ 'contents ' ,
310317 ]));
311318
312319 return response ('' , 204 );
0 commit comments