title: How to order by eager loaded relationship in Laravel 5.5?
body: <p>The code below works perfectly and displays all products with discounts in JSON Format for my API. But I want the result ordered by id in the discounts table. Something like <code>orderBy('discount.id', 'desc')</code>. Can anyone provide a solution for this? How it is possible to use orderBy with <code>id</code> column in <code>discount</code> table using <code>has()</code>?</p>
  <pre><code>public function promotions()
  {
      return $this-&gt;prepareResult(true, Product::has('discount')-&gt;where([
          'company_id' =&gt; 1, 'is_active' =&gt; 1
      ])-&gt;with('category')-&gt;with('discount')-&gt;get(), [], &quot;All Promotions&quot;);
  }
  </code></pre>