From 35057a40fbd06266efbfcdd3612ee7d581bf952e Mon Sep 17 00:00:00 2001 From: Butschster Date: Thu, 26 May 2016 22:55:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=20WidgetRepository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Http/Controllers/WidgetController.php | 14 +++++-------- src/Repository/WidgetRepository.php | 24 ++++++++--------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/Http/Controllers/WidgetController.php b/src/Http/Controllers/WidgetController.php index f4b6b7f..7ad7763 100644 --- a/src/Http/Controllers/WidgetController.php +++ b/src/Http/Controllers/WidgetController.php @@ -25,7 +25,7 @@ public function getIndex(WidgetManager $widgetManager, WidgetRepository $reposit { Meta::loadPackage('editable'); - $query = $repository->getModel()->newQuery(); + $query = $repository->query(); $widgetTypeLinks = [ link_to_route( @@ -91,10 +91,8 @@ public function getCreate(WidgetManager $widgetManager, $type = 'html') */ public function postCreate(WidgetRepository $repository) { - $data = $this->request->all(); - - $repository->validateOnCreate($data); - $widget = $repository->create($data); + $repository->validateOnCreate($this->request); + $widget = $repository->create($this->request->all()); return $this->smartRedirect([$widget]) ->with('success', trans($this->wrapNamespace('core.messages.created'), [ @@ -127,10 +125,8 @@ public function getEdit(WidgetRepository $repository, $id) */ public function postEdit(WidgetRepository $repository, $id) { - $data = $this->request->all(); - - $repository->validateOnUpdate($data); - $widget = $repository->update($id, $data); + $repository->validateOnUpdate($id, $this->request); + $widget = $repository->update($id, $this->request->all()); return $this->smartRedirect([$widget]) ->with('success', trans($this->wrapNamespace('core.messages.updated'), [ diff --git a/src/Repository/WidgetRepository.php b/src/Repository/WidgetRepository.php index 7840414..e4e837c 100644 --- a/src/Repository/WidgetRepository.php +++ b/src/Repository/WidgetRepository.php @@ -3,6 +3,7 @@ namespace KodiCMS\Widgets\Repository; use DB; +use Illuminate\Http\Request; use KodiCMS\Widgets\Model\Widget; use KodiCMS\CMS\Repository\BaseRepository; @@ -17,34 +18,25 @@ public function __construct(Widget $model) } /** - * @param array $data - * - * @return bool - * @throws \KodiCMS\CMS\Exceptions\ValidationException + * @param Request $request */ - public function validateOnCreate(array $data = []) + public function validateOnCreate(Request $request) { - $validator = $this->validator($data, [ + $this->validate($request, [ 'name' => 'required|max:255', 'type' => 'required', ]); - - return $this->_validate($validator); } /** - * @param array $data - * - * @return bool - * @throws \KodiCMS\CMS\Exceptions\ValidationException + * @param int $id + * @param Request $request */ - public function validateOnUpdate(array $data = []) + public function validateOnUpdate($id, Request $request) { - $validator = $this->validator($data, [ + $this->validate($request, [ 'name' => 'required|max:255', ]); - - return $this->_validate($validator); } /**