add support for editing service options
This commit is contained in:
parent
4e60adc875
commit
e42547a1ff
3 changed files with 116 additions and 23 deletions
|
@ -107,7 +107,19 @@ class ServiceController extends Controller
|
|||
|
||||
public function postOption(Request $request, $option)
|
||||
{
|
||||
// editing option
|
||||
try {
|
||||
$repo = new ServiceRepository\Option;
|
||||
$repo->update($option, $request->except([
|
||||
'_token'
|
||||
]));
|
||||
Alert::success('Option settings successfully updated.')->flash();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.option', $option)->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to modify this option.')->flash();
|
||||
}
|
||||
return redirect()->route('admin.services.option', $option)->withInput();
|
||||
}
|
||||
|
||||
public function postOptionVariable(Request $request, $option, $variable)
|
||||
|
|
|
@ -42,7 +42,31 @@ class Option
|
|||
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$option = Models\ServiceOptions::findOrFail($id);
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'name' => 'sometimes|required|string|max:255',
|
||||
'description' => 'sometimes|required|string|min:1',
|
||||
'tag' => 'sometimes|required|string|max:255',
|
||||
'executable' => 'sometimes|string|max:255',
|
||||
'docker_image' => 'sometimes|required|string|max:255',
|
||||
'startup' => 'sometimes|string'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException($validator->errors());
|
||||
}
|
||||
|
||||
if (isset($data['executable']) && empty($data['executable'])) {
|
||||
$data['executable'] = null;
|
||||
}
|
||||
|
||||
if (isset($data['startup']) && empty($data['startup'])) {
|
||||
$data['startup'] = null;
|
||||
}
|
||||
|
||||
$option->fill($data);
|
||||
$option->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue