title: Laravel belongsToMany where doesn't have one of
body: <p>I have two tables: <code>categories</code> and <code>videos</code>, I then have a pivot table for these as it's a belongsToMany relationship.</p>
  
  <p>What I'm trying to do is get all of the videos where there isn't a single instance of the video being in one of many categories.</p>
  
  <p>e.g.</p>
  
  <ul>
  <li>Video 1 is in category 1, 2 and 3. </li>
  <li>Video 2 is in category 1 and 3.</li>
  <li>Video 3 is in category 1.</li>
  </ul>
  
  <p>I want to get the video which is NOT in category 2 or 3, meaning this will return Video 3.</p>
  
  <p>What I've tried so far, which doesn't give the intended result, this is because another row is still found for Video 1 and 2, as they are in Category 1:</p>
  
  <pre><code>Video::whereHas('categories', function($query) {
      $query-&gt;whereNotIn('category_id', [2,3]);
  })-&gt;take(25)-&gt;get();
  </code></pre>
  
  <p>The query populated from this is:</p>
  
  <pre><code>select * from `videos` where exists (select * from `categories` inner join 
  `category_video` on `categories`.`id` = `category_video`.`category_id` where 
  `videos`.`id` = `category_video`.`video_id` and `category_id` != ? and 
  `category_id` != ? and `categories`.`deleted_at` is null) and `videos`.`deleted_at` 
  is null order by `created_at` desc limit 25
  </code></pre>