title: Laravel Eloquent model with multiple relations
body: <p>I have a requirement to build a task object that can have multiple relations</p>
  
  <pre><code>A Task can have these relations (note even though some say required they are actually optional)
  
  -- itemA_required // this can have many entries
  -- itemA_optional // this can have many entries
  -- itemB_required // this can have many entries
  -- itemB_optional // this can have many entries
  -- itemC_required // this can have many entries
  -- itemC_optional // this can have many entries
  -- itemD_required // this can have many entries
  -- itemD_optional // this can have many entries
  </code></pre>
  
  <p>I then have tables like this</p>
  
  <pre><code>task -- id|name|description
  
  itemA -- id|name|description
  itemB -- id|name|description
  itemC -- id|name|description
  itemD -- id|name|description
  
  task_itemA_required  -- id|task_id| itema_id
  task_itemA_optional  -- id|task_id| itema_id
  
  task_itemB_required  -- id|task_id| itemb_id
  task_itemB_optional  -- id|task_id| itemb_id
  
  task_itemC_required  -- id|task_id| itemc_id
  task_itemC_optional  -- id|task_id| itemc_id
  
  task_itemD_required  -- id|task_id| itemd_id
  task_itemD_optional  -- id|task_id| itemd_id
  </code></pre>
  
  <p>And models to go with this</p>
  
  <pre><code>task
  itemA
  itemB
  itemC
  itemD
  task_itemA_required
  task_itemA_optional
  task_itemB_required
  task_itemB_optional
  task_itemC_required
  task_itemC_optional
  task_itemD_required
  task_itemD_optional
  </code></pre>
  
  <p>The Task model has methods like this</p>
  
  <pre><code>public function ItemARequired()
  {
      return $this-&gt;hasMany('Models\ItemARequired');
  }
  public function ItemAOptional()
  {
      return $this-&gt;hasMany('Models\ItemAOptional');
  }
  </code></pre>
  
  <p>My questions are</p>
  
  <p>Is this the best way to go about doing this? The large number of model doesn't make this seem very 'Eloquent'.</p>
  
  <p>If this is correct way to go about this, how do I query for a task so it returns all of the relations and the id, name and description that goes with the related item? Does this require using something like this for each kind of relation in the Task model? I've tried variations of this and haven't gotten it to work. I guess I don't really understand the eloquent way of doing this.</p>
  
  <pre><code>public function ItemARequired()
  {
      return $this-&gt;hasManyThrough('App\ItemA', 'App\task_itemA_required');
  }
  </code></pre>
  
  <p>Hope what I have written here makes sense.</p>