title: Laravel - get the data in a certain order…
body: <p>I have a question about Laravel - Eloquent….</p>
  
  <p>I have a table that has (amongst other things)</p>
  
  <ul>
  <li>id</li>
  <li>name (varchar)</li>
  <li>position (int)</li>
  <li>parent (int) -> id of the parent page (which results in 0 when it is part of the main menu)  </li>
  </ul>
  
  <p>My goal didn’t seem to me as difficult but I don’t get it right….
  I need to do the following:</p>
  
  <ul>
  <li>Page in position 1
  
  <ul>
  <li>Child 1</li>
  <li>Child 2</li>
  </ul></li>
  <li>Page in position 2</li>
  <li>Page in position 3
  
  <ul>
  <li>Child 1</li>
  </ul></li>
  <li>Page in position 4</li>
  </ul>
  
  <p>Example Table:</p>
  
  <pre><code>+----+--------+------+  
  | ID |Position|Parent|  
  +----+--------+------+  
  | 1  |   3    |  0   |
  | 2  |   2    |  0   |
  | 3  |   3    |  6   |
  | 4  |   1    |  6   |
  | 5  |   2    |  6   |
  | 6  |   1    |  0   |
  +----+--------+------+
  </code></pre>
  
  <p>Should result in:</p>
  
  <p>6<br>
   - 4<br>
   - 5<br>
   - 3<br>
  2<br>
  1   </p>
  
  <p>In fact, in my first foreach, I should be able to do this:</p>
  
  <pre><code>    if $page-&gt;children-&gt;count() &gt; 0
  </code></pre>
  
  <p>I tried a lot of different things, in all ways possible but I don’t get to the result I want……
  If someone has a solution for me, I will be happy and very grateful :D</p>
  
  <p>Thank you in advance</p>