how to store ID with jquery not using the hidden input, because the validation in Laravel can not read or send errors with the hidden input.
CodePudding user response:
If by "hidden input" you mean an input tag with type="hidden"
then Laravel can absolutely read and validate against that. It does so with CSRF tokens and spoofing request methods.
Typically IDs would be included in the URL like: PUT /posts/123/comments/456
however if you really need to put an ID in the form and not let the user change it then a hidden input is a good way to do it.
Unfortunately there is no way that I can think of to use jQuery to add the ID to a html
form unless you are sending the request through JavaScript in which case you can add it to the FormData
object that gets sent:
const form = new FormData(document.querySelector('form'));
form.append('id', 123);
$.ajax({
type: "PUT",
enctype: 'multipart/form-data',
url: "/url",
data: data,
});