kamal kamal - 1 month ago 8
Javascript Question

How to pass js array with post request on form submit to controller in Laravel?

I have multiple js arrays which need to pass to controller on form submit. Is it possible to pass these arrays to controller with post request without using AJAX?

Answer

On submit you could convert these arrays to JSON and store this in a hidden input field.

var myJsonString = JSON.stringify(yourArray);

In PHP convert the JSON string to PHP array with json_decode()

Comments