Completed model updates for Services
This commit is contained in:
parent
09d23deed6
commit
323f1d943f
26 changed files with 299 additions and 167 deletions
|
@ -39,7 +39,7 @@ class Variable
|
|||
|
||||
public function create($id, array $data)
|
||||
{
|
||||
$option = Models\ServiceOptions::findOrFail($id);
|
||||
$option = Models\ServiceOptions::select('id')->findOrFail($id);
|
||||
|
||||
$validator = Validator::make($data, [
|
||||
'name' => 'required|string|min:1|max:255',
|
||||
|
@ -67,21 +67,22 @@ class Variable
|
|||
$data['user_viewable'] = (isset($data['user_viewable']) && in_array((int) $data['user_viewable'], [0, 1])) ? $data['user_viewable'] : 0;
|
||||
$data['user_editable'] = (isset($data['user_editable']) && in_array((int) $data['user_editable'], [0, 1])) ? $data['user_editable'] : 0;
|
||||
$data['required'] = (isset($data['required']) && in_array((int) $data['required'], [0, 1])) ? $data['required'] : 0;
|
||||
$data['option_id'] = $option->id;
|
||||
|
||||
$variable = new Models\ServiceVariables;
|
||||
$variable->option_id = $option->id;
|
||||
$variable->fill($data);
|
||||
$variable = Models\ServiceVariables::create($data);
|
||||
|
||||
return $variable->save();
|
||||
return $variable;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$variable = Models\ServiceVariables::findOrFail($id);
|
||||
$variable = Models\ServiceVariables::with('serverVariables')->findOrFail($id);
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
Models\ServerVariables::where('variable_id', $variable->id)->delete();
|
||||
foreach($variable->serverVariables as $svar) {
|
||||
$svar->delete();
|
||||
}
|
||||
$variable->delete();
|
||||
|
||||
DB::commit();
|
||||
|
@ -125,7 +126,18 @@ class Variable
|
|||
$data['user_editable'] = (isset($data['user_editable']) && in_array((int) $data['user_editable'], [0, 1])) ? $data['user_editable'] : $variable->user_editable;
|
||||
$data['required'] = (isset($data['required']) && in_array((int) $data['required'], [0, 1])) ? $data['required'] : $variable->required;
|
||||
|
||||
$variable->fill($data);
|
||||
// Not using $data because the function that passes into this function
|
||||
// can't do $requst->only() due to the page setup.
|
||||
$variable->fill([
|
||||
'name' => $data['name'],
|
||||
'description' => $data['description'],
|
||||
'env_variable' => $data['env_variable'],
|
||||
'default_value' => $data['default_value'],
|
||||
'user_viewable' => $data['user_viewable'],
|
||||
'user_editable' => $data['user_editable'],
|
||||
'required' => $data['required'],
|
||||
'regex' => $data['regex'],
|
||||
]);
|
||||
|
||||
return $variable->save();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue