Skip to content
Advertisement

How to solve Array to string conversion Error?

here user can select multiple foods. i want to save those food items to the database. I have column named “food” in the database i want to save all those selected food items in this column. just like this enter image description here . Right now I am getting this error Array to string conversion. If Anyone knows how to fix it please tell me.

JavaScript
JavaScript

Advertisement

Answer

If you’re simply trying to save the food list as a comma separated string:

JavaScript

Or better yet, add the food attribute to your models $casts property to automatically handle the conversion between an array and string.

See the docs here for casting details.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement