Skip to content

Commit

Permalink
Add the option to separate the validation by sections
Browse files Browse the repository at this point in the history
  • Loading branch information
eliurkis committed Jan 26, 2018
1 parent e710552 commit b0f9793
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected function manageFiles($row, $request)

public function store(Request $request)
{
$this->validateRequest($request);
$this->validateRequest($request, 'store');

DB::beginTransaction();

Expand Down Expand Up @@ -222,7 +222,7 @@ public function edit($id)

public function update(Request $request, $id)
{
$this->validateRequest($request);
$this->validateRequest($request, 'update');

DB::beginTransaction();

Expand Down Expand Up @@ -477,8 +477,9 @@ protected function prepareLinks()

/**
* @param Request $request
* @param $type
*/
protected function validateRequest($request)
protected function validateRequest($request, $type)
{
$validations = [
'rules' => [],
Expand All @@ -487,8 +488,15 @@ protected function validateRequest($request)
];

foreach ($this->fields as $field => $options) {
if (isset($options['validation'])) {
$validations['rules'][$field] = $options['validation'];
$validation = null;
if (isset($options['validation'][$type])) {
$validation = $options['validation'][$type];
} elseif (isset($options['validation']) && is_string($options['validation'])) {
$validation = $options['validation'];
}

if ($validation != '') {
$validations['rules'][$field] = $validation;
$validations['customAttributes'][$field] = $options['label'];
}
}
Expand Down

0 comments on commit b0f9793

Please sign in to comment.