I have 3 tables tests, questions, options.
As you can imagine
- a test has many questions
- a question belongs to a test
- a question has many options
- an option belongs to a question
These relations are set up in the models already.
I got the data from the front end in this form:
array:3 [
"name" => "First Test"
"preparation" => "First Test prep"
"questions" => array:2 [
0 => array:2 [
"title" => "Some question"
"options" => array:4 [
0 => "a"
1 => "b"
2 => "c"
3 => "d"
]
]
1 => array:2 [
"title" => "Another question"
"options" => array:4 [
0 => "e"
1 => "f"
2 => "g"
3 => "h"
]
]
]
]
This data perfectly represents these relationships. In fact if I were using a NoSql database I would simply store this in the database.
My question is "what is the best way to store all of this data at once while using eloquent in Laravel"?
Note: It is in the form of Laravel's collection.