title: Sort the parent model based on the child model / relationship
body: <p>I have a model called <code>appointments</code>, each appointment has an <code>option_id</code> that is linked through a one to one relationship and the <code>option_id</code> can also be <code>null</code>. The option model has a property <code>datetime_start</code>. I want to sort the appointments based on the <code>option.datetime_start</code>. </p>
  
  <p>Here is my code :</p>
  
  <pre><code>$appointments = $user-&gt;appointments()
  -&gt;with(['option'
  ])
  -&gt;get();
  </code></pre>
  
  <p>Edit : </p>
  
  <p>Appointment model :</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Appointment extends Model
  {
     /**
           * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
     public function option()
     {
       return $this-&gt;hasOne(Option::class, 'id', 'option_id');
     }
  }
  </code></pre>
  
  <p>Option model :</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Option extends Model
  {
      protected     $fillable = ["appointment_id",
                                 "datetime_start"
      ];
  
      public function appointment()
      {
          return $this-&gt;belongsTo(Appointment::class, 'id','appointment_id');
      }
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>