diff --git a/app/Http/Controllers/Admin/AssociateWidget.php b/app/Http/Controllers/Admin/AssociateWidget.php new file mode 100644 index 00000000..dd664464 --- /dev/null +++ b/app/Http/Controllers/Admin/AssociateWidget.php @@ -0,0 +1,59 @@ +id); + $widgets = Widget::paginate(25); + + return view('admin.widgets.association', [ + 'widgetArea' => $area, + 'widgets' => $widgets, + 'associatedWidgetIds' => $associatedWidgetIds + ]); + } + + public function makeAssociation($widgetId, $widgetAreaId) + { + try { + WidgetInWidgetArea::create(['widget_id' => $widgetId, 'widget_area_id' => $widgetAreaId]); + } catch (QueryException $e) { + return redirect() + ->route('widgets.associate', ['widgetArea' => $widgetAreaId]) + ->with('error', trans('admin/widgets.associationExists')); + } + + return redirect() + ->route('widgets.associate', ['widgetArea' => $widgetAreaId]) + ->with('success', trans('admin/widgets.successfullyAssociated')); + } + + public function deleteAssociation($widgetId, $widgetAreaId) + { + $widgetInArea = WidgetInWidgetArea::where('widget_id', $widgetId) + ->where('widget_area_id', $widgetAreaId); + + if ($widgetInArea->count() == 0) { + return redirect() + ->route('widgets.associate', ['widgetArea' => $widgetAreaId]) + ->with('error', trans('admin/widgets.associationDoesNotExists')); + } + + $widgetInArea->delete(); + + return redirect() + ->route('widgets.associate', ['widgetArea' => $widgetAreaId]) + ->with('success', trans('admin/widgets.successfullyDeassociated')); + } +} diff --git a/resources/views/admin/widgets/association.blade.php b/resources/views/admin/widgets/association.blade.php new file mode 100644 index 00000000..624b58b5 --- /dev/null +++ b/resources/views/admin/widgets/association.blade.php @@ -0,0 +1,79 @@ +@extends('admin.layout') + +@section('pageName', @trans('admin/widgets.overview')) + +@section('content') +
+ {{trans(call_user_func([$widget->widget_type_handler, 'getName']))}} +
++ {{str_limit($widget->description, 150)}} +
+ + ++ {{$widgetArea->description}} +
+ +