title: laravel orderby nested related model
body: <p>I have model with name <code>"Date"</code> which has relationship <code>(one-to-one)</code> with <code>"Tour"</code> and <code>"Tour"</code> Model has relationship  <code>(many-to-many)</code> with <code>"Type"</code> Model.
  I want to order my Date Records Based on <code>"Type"</code> name. Unfortunately I don't have any clue to do it with eloquent.</p>
  
  <p><code>Date model:</code></p>
  
  <pre><code>public function Tour()
  {
      return $this-&gt;belongsTo('\App\Tour');
  }
  </code></pre>
  
  <p><code>Tour model:</code></p>
  
  <pre><code>public function Date()
      {
          return $this-&gt;hasOne('\App\Date','tour_id');
      }
   public function Types()
      {
          return $this-&gt;belongsToMany('\App\Type');
      }
  </code></pre>
  
  <p><code>Type model:</code></p>
  
  <pre><code>public function Tours()
      {
          return $this-&gt;belongsToMany('\App\Tour');
      }
  </code></pre>
  
  <p>and my <code>controller</code> for output:</p>
  
  <pre><code>public function tourList()
      {
  
          $dates = new Date();
          $dates = $dates-&gt;orderBy('id','asc')
              -&gt;paginate(6)
              -&gt;appends([
              'sort_price' =&gt; request('sort_price'),
              'minmax' =&gt; request('minmax'),
              'type' =&gt; request('type')
          ]);
          return view('primary.Tour.list', compact(['dates']));
  }
  </code></pre>