add support for variable creation and deletion
This commit is contained in:
parent
dcf2f6fa0a
commit
48b9bc0c52
5 changed files with 198 additions and 4 deletions
|
@ -202,6 +202,34 @@ class ServiceController extends Controller
|
|||
return redirect()->route('admin.services.option', [$service, $option])->withInput();
|
||||
}
|
||||
|
||||
public function getNewVariable(Request $request, $service, $option)
|
||||
{
|
||||
return view('admin.services.options.variable', [
|
||||
'service' => Models\Service::findOrFail($service),
|
||||
'option' => Models\ServiceOptions::where('parent_service', $service)->where('id', $option)->firstOrFail()
|
||||
]);
|
||||
}
|
||||
|
||||
public function postNewVariable(Request $request, $service, $option)
|
||||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Variable;
|
||||
$repo->create($option, $request->except([
|
||||
'_token'
|
||||
]));
|
||||
Alert::success('Successfully added new variable to this option.')->flash();
|
||||
return redirect()->route('admin.services.option', [$service, $option])->withInput();
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.option.variable.new', [$service, $option])->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occurred while attempting to add this variable.')->flash();
|
||||
}
|
||||
return redirect()->route('admin.services.option.variable.new', [$service, $option])->withInput();
|
||||
}
|
||||
|
||||
public function newOption(Request $request, $service)
|
||||
{
|
||||
return view('admin.services.options.new', [
|
||||
|
@ -227,4 +255,19 @@ class ServiceController extends Controller
|
|||
return redirect()->route('admin.services.option.new', $service)->withInput();
|
||||
}
|
||||
|
||||
public function deleteVariable(Request $request, $service, $option, $variable)
|
||||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Variable;
|
||||
$repo->delete($variable);
|
||||
Alert::success('Deleted variable.')->flash();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to delete that variable.')->flash();
|
||||
}
|
||||
return redirect()->route('admin.services.option', [$service, $option]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -392,10 +392,24 @@ class AdminRoutes {
|
|||
'uses' => 'Admin\ServiceController@deleteOption'
|
||||
]);
|
||||
|
||||
$router->get('/service/{service}/option/{option}/variable/new', [
|
||||
'as' => 'admin.services.option.variable.new',
|
||||
'uses' => 'Admin\ServiceController@getNewVariable'
|
||||
]);
|
||||
|
||||
$router->post('/service/{service}/option/{option}/variable/new', [
|
||||
'uses' => 'Admin\ServiceController@postNewVariable'
|
||||
]);
|
||||
|
||||
$router->post('/service/{service}/option/{option}/variable/{variable}', [
|
||||
'as' => 'admin.services.option.variable',
|
||||
'uses' => 'Admin\ServiceController@postOptionVariable'
|
||||
]);
|
||||
|
||||
$router->get('/service/{service}/option/{option}/variable/{variable}/delete', [
|
||||
'as' => 'admin.services.option.variable.delete',
|
||||
'uses' => 'Admin\ServiceController@deleteVariable'
|
||||
]);
|
||||
});
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue