I don't have a clue how to make laravel validate stop validation after first error occurs and then return only one error
Rules with val_ prefix are my custom rules.
I need to display only error for pesel field if the pesel field is empty('required' rule)
Could anyone tell me how can I reach that ?
$this->validate($request, [
'pesel'=> 'bail|required|val_pesel',
'dane_os' => 'required',
'id_project' => 'required',
'imie' => 'required|val_imie',
'nazwisko'=>'required|val_nazwisko',
'nazwisko_matki'=>'required|val_nazwisko_matki'
]);
MY VALIDATION CODE
Validator::extend('val_pesel',function($attribute,$value,$parameters,$validator)
{
$val = DB::select('select * from `wyborca` where pesel = "'.$value.'" ; ');
if(empty($val))
{
return false;
}
else {
return true;
}
});
Validator::extend('val_imie',function($attribute,$value,$parameters,$validator)
{
$test = $validator->getData();
$pesel = $test['pesel'];
$imie = $test['imie'];
$val = DB::select('select * from `wyborca` where pesel = "'.$pesel.'" and imie = "'.$imie.'" ; ');
if(empty($val))
{
return false;
}
else {
return true;
}
});
Validator::extend('val_nazwisko',function($attribute,$value,$parameters,$validator)
{
$test = $validator->getData();
$pesel = $test['pesel'];
$nazwisko = $test['nazwisko'];
$val = DB::select('select * from `wyborca` where pesel = "'.$pesel.'" and nazwisko = "'.$nazwisko.'" ; ');
if(empty($val))
{
return false;
}
else {
return true;
}
});
Validator::extend('val_nazwisko_matki',function($attribute,$value,$parameters,$validator)
{
$test = $validator->getData();
$pesel = $test['pesel'];
$nazwisko_matki = $test['nazwisko_matki'];
$val = DB::select('select * from `wyborca` where pesel = "'.$pesel.'" and nazwisko_matki = "'.$nazwisko_matki.'" ; ');
if(empty($val))
{
return false;
}
else {
return true;
}
});
Validator::extend('vote_exists',function($attribute,$value,$parameters,$validator)
{
$test = $validator->getData();
$pesel = $test['pesel'];
$val = DB::select('select * from `glosy` where pesel = "'.$pesel.'" ; ');
if(empty($val))
{
return false;
}
else {
return true;
}
});
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…