FIX: fix creating widgets
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace App\CMS\Repositories\Widgets;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Widgets\Widget as WidgetModel;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
class Widget
|
||||
{
|
||||
public function createNew(WidgetType $widgetType, Request $request)
|
||||
{
|
||||
$data = $request->except('_token');
|
||||
|
||||
// create new widget
|
||||
$widget = new WidgetModel();
|
||||
$widget->widget_type_handler = $widgetType->handler;
|
||||
$widget->user_id = \Auth::user()->id;
|
||||
$widget->name = $data['name'];
|
||||
$widget->description = $data['description'];
|
||||
$widget->container_class = $data['containerClass'];
|
||||
$widget->container_id = $data['containerId'];
|
||||
$widget->settings = json_encode(call_user_func([$widgetType->handler, 'save'], $request));
|
||||
|
||||
// save into database
|
||||
$widget->save();
|
||||
|
||||
// fire event with newly created widget
|
||||
Event::fire(new \App\Events\CreateNewWidget($widget));
|
||||
|
||||
return $widget;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin\Widgets;
|
||||
|
||||
use App\CMS\Repositories\Widgets\Widget;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Http\Requests\NewWidgetRequest;
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetType;
|
||||
use App\CMS\Widgets\Exceptions\MissingParameterException;
|
||||
|
||||
class CreateNewWidget extends Controller
|
||||
{
|
||||
@@ -54,9 +54,9 @@ class CreateNewWidget extends Controller
|
||||
} catch (MissingParameterException $e) {
|
||||
// user omitted some value
|
||||
return $this->invalidWidget($type, $e->getMessage());
|
||||
} catch (\Exception $e) {
|
||||
// something went wrong
|
||||
return $this->invalidWidget($type, trans('admin/widgets.cannotSave', ['exception' => $e->getMessage()]));
|
||||
// } catch (\Exception $e) {
|
||||
// // something went wrong
|
||||
// return $this->invalidWidget($type, trans('admin/widgets.cannotSave', ['exception' => $e->getMessage()]));
|
||||
}
|
||||
|
||||
// redirect with success notification
|
||||
|
||||
Reference in New Issue
Block a user