Hello, I have a form with select name "interests" and i present multiple options so i am using interests[] array
When i try to insert it into database, i am getting error saying "trying to store array into string" I know what's wrong here and i can fix this if i assign each field value manually like $user->username = Input::get('username');
but i want to use Input::all();
Is there any way to assign array to string (even after converting interests[] array into a string) and use Input::all(); ?
Any help is appreciated :)
Thanks.
How are you storing these "interests" in your database? Have you set them up as a one-to-many or many-to-many relation?
Also, it would probably be best to specify exactly the fields you're populating in your model, instead of using Input::all(), to avoid injection exploits.
Hi, I am planning to store them as comma seperated values in a string.
If you're determined to use Input::all() you could set an event listener on your model and change the value of the array before saving... Change it to json, maybe, using json_encode().
http://laravel.com/docs/eloquent#model-events
Also, don't forget to protect the app from mass injection.
Yes, already protecting and accepting only certain fields with $protected
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community