I need to show the errors when validating the data, and I only show information that I do not need as well.
The given data was invalid. {"PERS_varDNI": ["The DNI must have 8 digits "]," PERS_varApPaterno ": [" Enter the Paternal Last Name "], "PERS_varApMaterno": ["Enter the Maternal Last Name"], "PERS_varName": ["Enter Names"]}
I'd just like to show
"The DNI must have 8 digits", "Enter the Maternal Surname", "Enter the Paternal Last Name", "Enter the Names"
this is the form
<span v-for="error in errors" class="text-danger">@{{ error }}</span>
I get the error here:
createPersona: function(){
var url='personas';
var persona=this.newPersona;
axios.post(url,persona).then(response=>{
this.getPersonas();
this.newPersona={PERS_varDNI: '', PERS_varApPaterno: '', PERS_varApMaterno: '', PERS_varNombres: ''},
this.errors=[];
$('#createPersona').modal('hide');
toastr.success('Nueva persona creada con exíto');
}).catch(error=>{
this.errors=error.response.data
});
}
and this is the controller:
public function store(Request $request)
{
//
$messages = [
'PERS_varDNI.required' => 'Debe ingresar el dni',
'PERS_varDNI.unique' => 'El DNI ya esta registrado',
'PERS_varDNI.integer' => 'El DNI solo debe tener numeros',
'PERS_varDNI.between' => 'El DNI debe tener 8 dígitos',
'PERS_varApPaterno.required' => 'Ingrese el Apellido Paterno',
'PERS_varApMaterno.required' => 'Ingrese el Apellido Materno',
'PERS_varNombres.required' => 'Ingrese los Nombres',
];
$rules=[
'PERS_varDNI' => 'required|unique:personas|integer|between:9999999,99999999',
'PERS_varApPaterno' => 'required',
'PERS_varApMaterno' => 'required',
'PERS_varNombres' => 'required',
];
$this->validate($request,$rules,$messages);
Persona::create($request->all());
return;
}