Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanomatteo committed Sep 12, 2020
1 parent a4c14bf commit bccd6ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ $validated = Request::validate( [
'cityCode' => 'required',

// all rules on fiscal code
'fiscalCode' => 'required|codfisc:first_name=name,last_name=familyName,dob=dateOfBirth,sex,cityCode',
'fiscalCode' => 'required|codfisc:first_name=name,last_name=familyName,dob=dateOfBirth,sex=sex,cityCode=cityCode',
]);

$validated = Request::validate( [
Expand Down
41 changes: 23 additions & 18 deletions src/LaravelCodiceFiscale.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function registerValidator()
$msg = null;

$map = []; // create parameters map

foreach ($parameters as $i => $p) {
if ($i === 0 && strpos($p, '=') === false) {
$codfisc = $p;
Expand All @@ -69,7 +70,7 @@ public function registerValidator()
$attr = $p;
} else {
$p = explode('=', $p);
$map[$p[0]] = $p[1] ?? $p[0];
$map[$p[0]] = $p[1];
}
}

Expand All @@ -94,29 +95,33 @@ public function registerValidator()
$map = [$attr => $attribute];
}

$matchData = array_intersect_key($reqData, array_flip($map));
$errs = $cf->validate($matchData, $map, true);
if (!empty($map)) {

if (!empty($errs)) {
if ($attr) {
$msg .= __('laravel-codice-fiscale::codfisc.field-do-not-match');
} else {
$matchData = array_intersect_key($reqData, array_flip($map));
$errs = $cf->validate($matchData, $map, true);

if (!empty($msg)) {
$msg .= ', ';
}
$msg .= '(';
$err_fields = '';
foreach ($errs as $f) {
if (!empty($err_fields)) {
$err_fields .= ', ';
if (!empty($errs)) {
if ($attr) {
$msg .= __('laravel-codice-fiscale::codfisc.field-do-not-match');
} else {

if (!empty($msg)) {
$msg .= ', ';
}
$msg .= '(';
$err_fields = '';
foreach ($errs as $f) {
if (!empty($err_fields)) {
$err_fields .= ', ';
}
$err_fields .= __('laravel-codice-fiscale::codfisc.' . $f);
}
$err_fields .= __('laravel-codice-fiscale::codfisc.' . $f);
}

$msg .= $err_fields . ') ' . __('laravel-codice-fiscale::codfisc.do-not-match');
$msg .= $err_fields . ') ' . __('laravel-codice-fiscale::codfisc.do-not-match');
}
}
}

} else {
if ($attr) {
$msg .= __('laravel-codice-fiscale::codfisc.impossible-to-match') . ': ' . $cf['err'];
Expand Down

0 comments on commit bccd6ea

Please sign in to comment.