後如何停止驗證我沒有線索如何使出現第一個錯誤後laravel驗證停止驗證,然後返回只有一個錯誤Laravel第一個錯誤
規則與val_前綴是我的自定義規則做。
我需要爲PESEL場僅顯示錯誤,如果PESEL字段爲空(「必要」規則) 誰能告訴我,我怎麼能達到呢?
$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'
]);
我的驗證碼
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;
}
});
}
一切都看起來正確,你可以添加一些你的自定義規則的細節? –
如果'required'失敗或者您期待其他屬性上的驗證規則的其餘部分不能運行,您是否期望'val_pesel'不會運行? –
如何進行兩次驗證檢查?一個是pesel,一個是其他的。如果pesel驗證無效,則返回,否則繼續。 – Jeffrey