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