This is a piece of my code, to validate a form input:
public function saveData(Request $request){
$form_data = $request->all();
$validation_fields = [
'first_name' => 'required',
'last_name' => 'required',
'cod_fisc' => 'sometimes|required|size:16',
'p_iva' => 'sometimes|required|between:11,13'
];
$errorMsgs = [
'first_name.required' => 'Il campo Nome è obbligatorio.',
'last_name.required' => 'Il campo Cognome/Ragione sociale è obbligatorio.',
'cod_fisc.required' => 'Il campo Codice Fiscale deve contenere 16 caratteri',
'p_iva.required' => 'Il campo Partita Iva deve contenere 11 o 13 caratteri',
];
$validator = Validator::make($form_data, $validation_fields, $errorMsgs);
....
}
The whole project is written for Italian people, so all messages must be in Italian.
All works fine, but the two rules for cod_fisc and p_iva, that are binded to a "sometimes" rule, are displayed in English. My custom error messages are ignored.
Why?