Skip to content

Commit

Permalink
Fix invalid() and valid() methods. (issue #14646)
Browse files Browse the repository at this point in the history
invalid() and valid() methods where returning empty arrays
Issue link: laravel/framework#14646
  • Loading branch information
Carlos Alberto Bertholdo Carucce authored Aug 5, 2016
1 parent 70535fb commit 97c855c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,22 @@ protected function validate($attribute, $rule)
}
}

/**
* Generate a key map to determine the valid
* and invalid data
* @return array
*/
protected function getMessagesKeyMap()
{
$map = [];

foreach($this->messages()->toArray() as $key => $message){
$map []= explode('.', $key)[0];
}

return array_flip(array_unique($map));
}

/**
* Returns the data which was valid.
*
Expand All @@ -498,7 +514,7 @@ public function valid()
$this->passes();
}

return array_diff_key($this->data, $this->messages()->toArray());
return array_diff_key($this->data, $this->getMessagesKeyMap());
}

/**
Expand All @@ -512,7 +528,7 @@ public function invalid()
$this->passes();
}

return array_intersect_key($this->data, $this->messages()->toArray());
return array_intersect_key($this->data, $this->getMessagesKeyMap());
}

/**
Expand Down

0 comments on commit 97c855c

Please sign in to comment.