Reputation: 3677
I have a Laravel form which collectes education information. Initially form contains a set of fields(4-5 text boxes and select fileds) for storing one education related information, user can add multiple education related information by clicking add more button. I achieved this by using jquery(cloning and appending). The user is able to edit his details later, and I'm using the same form for the edit. So in a such a situation what is the best solution to populate the dynamically added fields. Is laravel provides a built in solution for this.
Upvotes: 1
Views: 190
Reputation: 163768
Do not store this data as JSON. In this case, if you'll need to use this data for some query (search, count etc), you'll need to rewrite all related logic, transform existing data etc.
What you want to do is to pass all fields as an array, transform it and store as multiple separated rows in DB. Also, normally you would want to store select fields values as foreign keys to other tables.
<input name="student[]">
Upvotes: 1
Reputation: 23
You can either decode it to JSON and store it within a column, mostly what I do is make a seperate table with a hasMany relation ship.
Fetch them and loop over them when you need to display them.
You can even go so far of storing the question a Table and make a relation between the new table also.
Upvotes: 1