-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
вынос логики создания и редактирования виджетов в Forms
- Loading branch information
1 parent
35057a4
commit 407914a
Showing
4 changed files
with
100 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace KodiCMS\Widgets\Http\Forms; | ||
|
||
use Illuminate\Http\Request; | ||
use KodiCMS\Widgets\Model\Widget; | ||
use KodiCMS\Widgets\Repository\WidgetRepository; | ||
use KodiComponents\Support\Http\Form; | ||
|
||
class CreateWidgetForm extends Form | ||
{ | ||
|
||
/** | ||
* @var WidgetRepository | ||
*/ | ||
protected $repository; | ||
|
||
/** | ||
* Form constructor. | ||
* | ||
* @param Request|null $request | ||
* @param WidgetRepository $repository | ||
*/ | ||
public function __construct(Request $request, WidgetRepository $repository) | ||
{ | ||
parent::__construct($request); | ||
|
||
$this->repository = $repository; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required|max:255', | ||
'type' => 'required', | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function labels() | ||
{ | ||
return trans('widgets::core.field'); | ||
} | ||
|
||
/** | ||
* Persist the form. | ||
* | ||
* @return Widget | ||
*/ | ||
public function persist() | ||
{ | ||
return $this->repository->create($this->request->all()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace KodiCMS\Widgets\Http\Forms; | ||
|
||
use KodiCMS\Widgets\Model\Widget; | ||
|
||
class UpdateWidgetForm extends CreateWidgetForm | ||
{ | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required|max:255', | ||
]; | ||
} | ||
|
||
/** | ||
* Persist the form. | ||
* | ||
* @return Widget | ||
*/ | ||
public function persist() | ||
{ | ||
return $this->repository->update( | ||
$this->request->route('id'), | ||
$this->request->all() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters