Add support for adding new service option
This commit is contained in:
parent
177bd4ec9d
commit
1e9bf1c220
8 changed files with 186 additions and 4 deletions
|
@ -47,7 +47,10 @@ class ServiceController extends Controller
|
|||
public function getIndex(Request $request)
|
||||
{
|
||||
return view('admin.services.index', [
|
||||
'services' => Models\Service::all()
|
||||
'services' => Models\Service::select(
|
||||
'services.*',
|
||||
DB::raw('(SELECT COUNT(*) FROM servers WHERE servers.service = services.id) as c_servers')
|
||||
)->get()
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -185,4 +188,29 @@ class ServiceController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
public function newOption(Request $request, $service)
|
||||
{
|
||||
return view('admin.services.options.new', [
|
||||
'service' => Models\Service::findOrFail($service),
|
||||
]);
|
||||
}
|
||||
|
||||
public function postNewOption(Request $request, $service)
|
||||
{
|
||||
try {
|
||||
$repo = new ServiceRepository\Option;
|
||||
$id = $repo->create($service, $request->except([
|
||||
'_token'
|
||||
]));
|
||||
Alert::success('Successfully created new service option.')->flash();
|
||||
return redirect()->route('admin.services.option', $id);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.option.new', $service)->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to add this service option.')->flash();
|
||||
}
|
||||
return redirect()->route('admin.services.option.new', $service)->withInput();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -370,6 +370,15 @@ class AdminRoutes {
|
|||
'uses' => 'Admin\ServiceController@deleteService'
|
||||
]);
|
||||
|
||||
$router->get('/option/new/{service}', [
|
||||
'as' => 'admin.services.option.new',
|
||||
'uses' => 'Admin\ServiceController@newOption'
|
||||
]);
|
||||
|
||||
$router->post('/option/new/{service}', [
|
||||
'uses' => 'Admin\ServiceController@postNewOption'
|
||||
]);
|
||||
|
||||
$router->get('/option/{id}', [
|
||||
'as' => 'admin.services.option',
|
||||
'uses' => 'Admin\ServiceController@getOption'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue