Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
edstevo committed Oct 12, 2017
1 parent 51741be commit 3f790de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Repositories/DaoBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ public function generate(bool $persist = true) : DaoGeneratorContract
*
* @return \EdStevo\Dao\Contracts\DaoValidator
*/
public function validate(array $rules = []) : DaoValidatorContract
public function validate(array $data = []) : DaoValidatorContract
{
return $this->validator->setRules($rules);
return $this->validator->setData($data);
}
}
36 changes: 17 additions & 19 deletions src/Repositories/DaoValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ class DaoValidator implements DaoValidatorContract
protected $dao;

/**
* Custom Validation Rules
* Custom Validation Data
*
* @var array
*/
protected $rules;
protected $data;

public function __construct(DaoBase $dao)
{
$this->dao = $dao;
$this->rules = [];
$this->data = [];
}

/**
Expand All @@ -40,23 +40,28 @@ public function __construct(DaoBase $dao)
*
* @return \EdStevo\Dao\Repositories\DaoValidator
*/
public function setRules($rules) : DaoValidator
public function setData($data) : DaoValidator
{
$this->rules = $rules;
if (empty($data))
{
$this->data = request()->all();
} else {
$this->data = $data;
}

return $this;
}

/**
* Validate the storing of a model
*
* @param array $data
* @param array $rules
*
* @return mixed
*/
public function store(array $data = [])
public function store(array $rules = [])
{
return $this->validate($this->dao->getStoreRules(), $data);
return $this->validate(array_merge($this->dao->getStoreRules(), $rules));
}

/**
Expand All @@ -66,9 +71,9 @@ public function store(array $data = [])
*
* @return mixed
*/
public function update(array $data = [])
public function update(array $rules = [])
{
return $this->validate($this->dao->getUpdateRules(), $data);
return $this->validate(array_merge($this->dao->getStoreRules(), $rules));
}

/**
Expand All @@ -79,16 +84,9 @@ public function update(array $data = [])
*
* @return mixed
*/
private function validate(array $rules, array $data = [])
private function validate(array $rules)
{
if (empty($data))
{
$data = request()->all();
}

$rules = array_merge($rules, $this->rules);

return Validator::make($data, $rules)->validate();
return Validator::make($this->data, $rules)->validate();
}

}

0 comments on commit 3f790de

Please sign in to comment.