public function saveAction($data, $id = 0)
{
if (!$id) {
$widget = Widget::create();
} else {
if (!($widget = Widget::find($id))) {
App::abort(404, 'Widget not found.');
}
}
if (empty($data['title'])) {
App::abort(400, 'Widget title empty.');
}
$widget->save($data);
return ['message' => 'success', 'widget' => $widget];
}