I am putting together an application which I work with laravel, for the use of java script use vue js and for sending data I use axios.
My problem is when I try to apply the rules of laravel, although the message returns to me, trying to pass this to an array does not take it and leaves it empty.
This is my controller code
public function store(Request $request)
{
$rules = [
'nombre' => 'required|min:3|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|min:6|max:16',
'passwordConfirm' => 'required|min:6|max:12|same:password',
'perfil' => 'required',
'estado' => 'required'
];
$this->validate($request, $rules);
$user = new User();
$user->nombre = $request->input('nombre');
$user->email = $request->input('email');
$user->password = Hash::make($request->input('password'));
$user->tipo_usuario = $request->input('perfil');
$user->estado = $request->input('estado');
$user->save();
}
This is my to send the information to the controller and receive the answer
registrarUsuario(){
let me = this;
axios.post('/users/registrar',{
nombre : this.nombre,
email : this.email,
password : this.password,
passwordConfirm : this.passwordConfirm,
perfil : this.perfil,
estado : this.estado
}).then(function (response) {
me.listarUsuario();
me.limpiar();
//console.log(error.response.data.errors);
}).catch(function (error) {
this.mensajes = this.error.response.data.errors;
console.log(mensajes);
});
},
and this is my code in html and vue js to show the messages that I can not show
<div v-show="mensajes">
<div class="alert alert-danger">
<ul>
<li v-for="mensaje in mensajes" :key="mensaje" v-text="mensaje"></li>
</ul>
</div>
</div>