add ability to create new service
This commit is contained in:
parent
e42547a1ff
commit
a50bb5da14
4 changed files with 146 additions and 2 deletions
|
@ -53,12 +53,27 @@ class ServiceController extends Controller
|
|||
|
||||
public function getNew(Request $request)
|
||||
{
|
||||
//
|
||||
return view('admin.services.new');
|
||||
}
|
||||
|
||||
public function postNew(Request $request)
|
||||
{
|
||||
//
|
||||
try {
|
||||
$repo = new ServiceRepository\Service;
|
||||
$id = $repo->create($request->except([
|
||||
'_token'
|
||||
]));
|
||||
Alert::success('Successfully created new service!')->flash();
|
||||
return redirect()->route('admin.services.service', $id);
|
||||
} catch (DisplayValidationException $ex) {
|
||||
return redirect()->route('admin.services.new')->withErrors(json_decode($ex->getMessage()))->withInput();
|
||||
} catch (DisplayException $ex) {
|
||||
Alert::danger($ex->getMessage())->flash();
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
Alert::danger('An error occured while attempting to add a new service.')->flash();
|
||||
}
|
||||
return redirect()->route('admin.services.new')->withInput();
|
||||
}
|
||||
|
||||
public function getService(Request $request, $service)
|
||||
|
|
|
@ -348,6 +348,15 @@ class AdminRoutes {
|
|||
'uses' => 'Admin\ServiceController@getIndex'
|
||||
]);
|
||||
|
||||
$router->get('/new', [
|
||||
'as' => 'admin.services.new',
|
||||
'uses' => 'Admin\ServiceController@getNew'
|
||||
]);
|
||||
|
||||
$router->post('/new', [
|
||||
'uses' => 'Admin\ServiceController@postNew'
|
||||
]);
|
||||
|
||||
$router->get('/service/{id}', [
|
||||
'as' => 'admin.services.service',
|
||||
'uses' => 'Admin\ServiceController@getService'
|
||||
|
|
|
@ -40,6 +40,31 @@ class Service
|
|||
//
|
||||
}
|
||||
|
||||
public function create(array $data)
|
||||
{
|
||||
$validator = Validator::make($data, [
|
||||
'name' => 'required|string|min:1|max:255',
|
||||
'description' => 'required|string',
|
||||
'file' => 'required|regex:/^[\w.-]{1,50}$/',
|
||||
'executable' => 'required|max:255|regex:/^(.*)$/',
|
||||
'startup' => 'required|string'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
throw new DisplayValidationException($validator->errors());
|
||||
}
|
||||
|
||||
if (Models\Service::where('file', $data['file'])->first()) {
|
||||
throw new DisplayException('A service using that configuration file already exists on the system.');
|
||||
}
|
||||
|
||||
$service = new Models\Service;
|
||||
$service->fill($data);
|
||||
$service->save();
|
||||
|
||||
return $service->id;
|
||||
}
|
||||
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$service = Models\Service::findOrFail($id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue