title: Laravel - Get records from one table that doesn't exist in another with a where clause attached
body: <p>I've got the following SQL tables (in MySQL):</p>
  
  <pre><code>students
  +-----+------------+
  | id  | first_name | 
  +-----+------------+
  | 01  | John       |
  +-----+------------+
  | 02  | Jane       | 
  +-----+------------+
  | 03  | Peter      | 
  +-----+------------+
  
  academics
  +-----+-----------+----------+------+
  | id  | year_start| year_end |status|
  +-----+-----------+----------+------+
  | 10  | 2016      | 2017     |1     |
  +-----+-----------+----------+------+
  | 20  | 2017      | 2018     |0     |
  +-----+-----------+----------+------+
  
  enrollments
  +----+------------+-------------+
  | id | student_id | academic_id |
  +----+------------+-------------+
  | 1  | 01         | 10          |
  +----+------------+-------------+
  | 2  | 02         | 20          |
  +----+------------+-------------+
  | 3  | 01         | 20          |
  +----+------------+-------------+
  </code></pre>
  
  <p>How do I get students from both the <code>students table</code> and the <code>enrollments table</code> who are not enrolled for the current academic year or of whom no records exists in the <code>enrollments table</code> for the current academic year.</p>
  
  <p>For now I can get the student form the <code>students table</code> who has no enrollment details in the <code>enrollments table</code> with this query:</p>
  
  <pre><code>$students = \DB::table('students')
          -&gt;select(
              'students.id',
              'first_name'
          )
          -&gt;leftJoin('enrollments','enrollments.student_id','=','students.id')
          -&gt;whereNull('enrollments.student_id')
          -&gt;get();
  </code></pre>
  
  <p>Based on the data in the table above this query will return student <code>Peter - 03</code>.</p>
  
  <p><em>BUT HOW CAN I GET STUDENTS WHO HAVE NO ENROLLMENT DETAILS FOR THE CURRENT ACADEMIC YEAR?</em></p>
  
  <p>This is how I determine the current academic year:</p>
  
  <pre><code>$current_academic = Academic::where('status', 1)-&gt;first();
  </code></pre>
  
  <p>With the existing query how do I join on the <code>academics table</code> so that I can query out students who have no enrollment records for the current academic year. 
  Will appreciate your earnest answers and suggestions.</p>