Change validation to controllers and partial

This commit is contained in:
Joseph Cohen
2015-01-09 20:21:29 -06:00
parent 996aceadcf
commit f47fb9823e
22 changed files with 117 additions and 208 deletions

View File

@@ -38,6 +38,24 @@ class DashIncidentController extends Controller
]);
}
/**
* Creates a new incident.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentAction()
{
$incident = Incident::create(Binput::get('incident'));
if (! $incident->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))
->with('errors', $incident->getErrors());
}
return Redirect::back()->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success')));
}
/**
* Shows the add incident template view.
*
@@ -60,19 +78,13 @@ class DashIncidentController extends Controller
$_template = Binput::get('template');
$template = IncidentTemplate::create($_template);
return Redirect::back()->with('template', $template);
}
if (! $template->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.failure')))
->with('errors', $template->getErrors());
}
/**
* Creates a new incident.
*
* @return \Illuminate\Http\RedirectResponse
*/
public function createIncidentAction()
{
$incident = Incident::create(Binput::get('incident'));
return Redirect::back()->withInput(Binput::all())->with('incident', $incident);
return Redirect::back()->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.add.success')));
}
/**
@@ -116,6 +128,12 @@ class DashIncidentController extends Controller
$_incident = Binput::get('incident');
$incident->update($_incident);
return Redirect::to('dashboard/incidents');
if (! $incident->isValid()) {
return Redirect::back()->withInput(Binput::all())
->with('title', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.templates.edit.failure')))
->with('errors', $incident->getErrors());
}
return Redirect::to('dashboard/incidents')->with('success', sprintf("<strong>%s</strong> %s", trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success')));
}
}