title: How to sort NULL values last using Eloquent in Laravel
body: <p>I've got a many to many relationship between my employees and groups table. I've created the pivot table, and all is working correctly with that. However, I've got a sortOrder column on my employees table that I use to determine the order in which they display. Employee with a value of 1 in the sortOrder column should be first, value of 2 should be second, so on. (Or backwards if sorted descending) The sortOrder column is a integer column that allows null values.</p>
  
  <p>I've set up my group model to sort the employees by the sort column, but I've run into a problem. The null values always are displayed first. I've tried using ISNULL and similar SQL methods in place of the regular "asc" or "desc" used, but I only get an error.</p>
  
  <p>Here's the code in my Group model:</p>
  
  <pre><code>class Group extends Eloquent {
  
  public function employees()
      {
          return $this-&gt;belongsToMany("Employee")-&gt;orderBy('sortOrder', 'asc');
      }
  }
  </code></pre>
  
  <p>And here's what I use in the controller to access my model:</p>
  
  <pre><code>$board = Group::find(6)-&gt;employees;
  </code></pre>
  
  <p>What's the trick in Laravel to sorting NULL values last?</p>