title: How to decrease amount of DB queries using nested list of items in <select> tag?
body: <p>Laravel 5.8: 
  I'm getting too much queries when I use nested list of items.</p>
  
  <p>This is for  menu in the View. I've done nested  menu of items but it seems to me it takes too much queries(10 extra queries for my list of 30 items) Although I used "eager loads".</p>
  
  <p>In the model:</p>
  
  <pre><code>public function children()
  {
      return $this-&gt;hasMany(Item::class, 'parent_id', 'id');
  }
  </code></pre>
  
  <p>Its Repository: (used eager loads [with])</p>
  
  <pre><code>public function getListOfItemTitles()
  {
      $columns = ['id', 'parent_id', 'title'];
  
      $result = $this-&gt;startConditions()
          -&gt;select($columns)
          -&gt;with(['children:id,title,parent_id'])
          -&gt;get();
      return $result;
  }
  </code></pre>
  
  <p>And the view:</p>
  
  <pre><code>&lt;select name="item_id" id="item_id" class="form-control" required&gt;
      @foreach($itemList as $itemOption)
          @if($itemOption-&gt;parent_id == 1)
              &lt;optgroup label="{{ $itemOption-&gt;title }}"&gt;
                  @foreach($itemOption-&gt;children as $children)
                      &lt;option value="{{ $children-&gt;id }}"&gt;
                          {{ $children-&gt;title }}
                      &lt;/option&gt;
                      @foreach($children-&gt;children as $subchildren)
                          &lt;option value="{{ $subchildren-&gt;id }}"&gt;
                              —{{ $subchildren-&gt;title }}
                          &lt;/option&gt;
                      @endforeach
                  @endforeach
              &lt;/optgroup&gt;
          @endif
      @endforeach
  &lt;/select&gt;
  </code></pre>
  
  <p>Here are my queries:</p>
  
  <pre><code>select `id`, `parent_id`, `title` from `items` where `items`.`deleted_at` is null
  select `id`, `title`, `parent_id` from `items` where `items`.`parent_id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30) and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 4 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 8 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 12 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 16 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 20 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 26 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 27 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 28 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 29 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  select * from `items` where `items`.`parent_id` = 30 and `items`.`parent_id` is not null and `items`.`deleted_at` is null
  </code></pre>
  
  <p>I'd be happy if you help me to decrease amount of queries.
  Any additional advice in this case would be very apreciated since I'm new in PhP &amp; Laravel.</p>