/**
  * @param WidgetRepository $repository
  * @param int              $handlerId
  *
  * @return mixed|void
  * @throws WidgetException
  */
 public function getHandle(WidgetRepository $repository, $handlerId)
 {
     event('handler.requested', [$handlerId]);
     $widget = $repository->findOrFail($handlerId);
     if (!$widget->isHandler()) {
         throw new WidgetException('Widget handler not found');
     }
     try {
         return app()->call([$widget->toWidget(), 'handle']);
     } catch (ValidationException $e) {
         return $this->throwValidationException($this->request, $e->getValidator());
     }
 }
 /**
  * @param WidgetRepository $repository
  */
 public function getListForPage(WidgetRepository $repository)
 {
     $pageId = (int) $this->getRequiredParameter('page_id');
     $widgets = $repository->getByPageId($pageId);
     $this->setContent($widgets);
 }
 /**
  * Persist the form.
  *
  * @return Widget
  */
 public function persist()
 {
     return $this->repository->create($this->request->all());
 }
 /**
  * @param WidgetRepository $repository
  * @param int          $id
  */
 public function getTemplate(WidgetRepository $repository, $id)
 {
     $widget = $repository->findOrFail($id);
     WYSIWYG::loadDefaultCodeEditor();
     $template = $widget->getDefaultFrontendTemplate();
     $content = null;
     if (!$template instanceof View) {
         $template = view($template);
     }
     $content = file_get_contents($template->getPath());
     $this->setContent('widgets.template', compact('content'));
 }