Skip to content

Commit

Permalink
Рефакторинг класса WidgetRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed May 26, 2016
1 parent e6fed82 commit 35057a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
14 changes: 5 additions & 9 deletions src/Http/Controllers/WidgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'), [
Expand Down Expand Up @@ -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'), [
Expand Down
24 changes: 8 additions & 16 deletions src/Repository/WidgetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace KodiCMS\Widgets\Repository;

use DB;
use Illuminate\Http\Request;
use KodiCMS\Widgets\Model\Widget;
use KodiCMS\CMS\Repository\BaseRepository;

Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 35057a4

Please sign in to comment.