1

I'm having troubles sending a multidimentional array from my view to controller, actually I have this array:

$array_data[$i] = ['providers_id'=>$chosen_providers[$i],'buy_prices'=>$buy_prices[$i],'total'=>$total;                                                
];

How can I send this to my controller?

I tried:

{{ Form::hidden('array_data[]',$array_data[$i]) }}

But I got htmlentities() expects parameter 1 to be string, array given error

Regards

1
  • check array_flatten() or you can send the array as a multi-dimensional array and then read the array as a multidimensional array in the view Commented Jul 29, 2017 at 4:38

2 Answers 2

2

You can pass your array using serialize(). and then unserialize() the value in your controller.

view:

 <input type="hidden" name="test" value="{{ serialize($arr) }}">

controller:

dd(unserialize($request->test));
Sign up to request clarification or add additional context in comments.

3 Comments

Thank u so much !
Please dont use this solution since anybody could modify your hidden input and thus create arbitrary variables, classes, etc. on your backend which is a security risk. If you have the data on rendering the form it would be better to store this array in the session and then use it later on form submit.
thanks your comment. you are right, I just show a procedure. but for the security issue, this code is not perfect.
0

Don't know much about laravel functions if there any other to pass array...

but here you can convert that array to string or json and in the controller you and decode again that to array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.