I have the following javascript: arreglos_grados
fix, which implements it in the following way: arreglos_grados = []
but I would like to validate with the Validator
of Laravel 5.5
if a field that I am inserting in the javascript fix is already registered .
I am sending my fix to the controller in the following way.
$('#agregar_grado').click(function (e) {
e.preventDefault();
var grado = {
id_count: 'id_' + count_grados,
grados: $('#grados option:selected').val(),
fecha_examen_grado: $("#fecha_examen_grado").val(),
fecha_obtencion_grado: $('#fecha_obtencion_grado').val(),
};
arreglos_grados.push(grado);
count_grados++;
$.ajax({
type: 'POST',
url: '{{ route('regMiembros.agregargrados') }}',
data: {
arreglos_grados.length ? arreglos_grados: null
},
success: function (data) {
if ($.isEmptyObject(data.errors)) {
$.smkAlert({
text: data.success,
type: 'success'
});
limpiarErroresGrados();
$('#lista_grados').append('<tr id="' + grado.id_count + '"><td style="text-align: center">' + $('#grados option:selected').text() + '</td><td style="text-align: center">' + $('#fecha_obtencion_grado').text() + '</td><td style="text-align: center">' + $('#fecha_examen_grado').text() + '</td><td style="text-align: center;"><button class="glyphicon glyphicon-trash" onclick="eliminarGrado(\'' + grado.id_count + '\');"></buton></td></tr>');
} else {
limpiarErroresGrados();
$.each(data.errors, function (index, value) {
$('#_' + index).text(value);
});
$.smkAlert({
text: "Existen errores de validación en los grados masónicos, por favor revise ",
type: 'danger'
});
}
},
error: function (jqXHR, textStatus, errorThrown) {
arreglos_grados.splice(arreglos_grados.length - 1, 1);
alerta(jqXHR.responseText);
}
});
});
In my controller I have raised my Validator
in the following way in my function of controller
$validator = Validator::make($request->all(), $rules, $messages, $attributes);
How can I validate elements that are within that array?