title: Laravel 4 sort by related model
body: <p>My project involves medical appointments using Laravel 4.  Each appointment is linked to a doctor, a patient, a status, and one or more insurance cards.</p>
  
  <p>So far this is working great:</p>
  
  <pre><code>$appointments = Appointment::
      with('doctor','patient','status','insurances')-&gt;
      orderBy($this-&gt;input['sidx'], $this-&gt;input['sord'])-&gt;
      paginate($this-&gt;input['rows']);
  </code></pre>
  
  <p>The challenge is, sorting only works as long as I am sorting an attribute of the appointment.  How would I adjust things if I wanted to sort by doctor.last_name or patient.last_name?</p>