I want user to provide postal code using input text field and despite of the white spaces he/she uses when providing the postal code I want it to pass validation if it is available in my database so I used the following code in my validator:
'postal_code' =>['required','string','max:7',Rule::exists('zipcodes','POSTAL_CODE')->where(function ($query) use($postalcode) {
return $query->whereRaw('replace(POSTAL_CODE,\' \',\'\')=? ',[str_replace(' ','',$postalcode)]);
})],
]);
but when I test the form I used it for it show error if I input aaa7fr but no error if I used aaa 7fr which is exactly in my database which I do not want and instead I want both to show no error. Would you please kindly tell me where is the wrong in my code and how to fix it?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire