title: How to use whereNotNull in controller while using with (' Many-to-many relationships') to show on the blade view?
body: <p>I try to show the 'categories' from <strong>Many to Many relationships</strong> and use
  <strong>whereNotNull</strong> at the same time but when I use <strong>whereNotNull</strong> to check that the users have approved then the <strong>categories</strong> from the <strong>relationships</strong> are disappeared in the blade view.</p>
  <p>If I have not put whereNotNull. The list of users who are vendors still appears (approved and waiting for approval both of them are showing in the view with the category relationships). When I use whereNotNull the blade view will show only approved users without category relationships.</p>
  <p><strong>The explanation pictures.</strong></p>
  <blockquote>
  <p><a href="https://www.234.in.th/images/2020/12/24/1f0ec6e871b484f9f.png" rel="nofollow noreferrer">When use whereNotNull click!</a></p>
  </blockquote>
  <blockquote>
  <p><a href="https://www.234.in.th/images/2020/12/24/2.png" rel="nofollow noreferrer">When not use whereNotNull click!</a></p>
  </blockquote>
  <p><strong>This is the view that I want to show the categories from the relationships.</strong></p>
  <pre class="lang-xml prettyprint-override"><code>@if(count($user-&gt;categories) &gt; 0)
       @foreach ($user-&gt;categories as $category)
         &lt;span class=&quot;badge badge-pill badge-info p-2 m-1&quot;&gt;{{ $category-&gt;name }}&lt;/span&gt;
       @endforeach
  @endif
  </code></pre>
  <p><strong>The UserController</strong></p>
  <pre class="lang-php prettyprint-override"><code>public function index()
  {
      $users = User::with('categories') // Eager loading
          -&gt;where('role', 'vendor')
          -&gt;whereNotNull('approved_at')     //If I put whereNotNull the categories will now showing
          -&gt;get();                            but If I delete it, the relationships will appear in the 
                                               view again.
      return view('admin.vendorDashboard')
          -&gt;with('categories', Categories::all())
          -&gt;with('users', $users);
      }
  }
  </code></pre>
  <p><strong>User Model</strong></p>
  <pre class="lang-php prettyprint-override"><code>public function categories()
  {
      return $this-&gt;BelongsToMany(Categories::class);
  }
  </code></pre>
  <p><strong>Categories Model</strong></p>
  <pre class="lang-php prettyprint-override"><code>public function users()
  {
      return $this-&gt;BelongsToMany(User::class);
  }
  </code></pre>
  <p><strong>User Table</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>User</th>
  <th>Approved_at</th>
  <th>Role</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>A</td>
  <td>2020-12-24 18:40:59</td>
  <td>Vendor</td>
  </tr>
  <tr>
  <td>2</td>
  <td>B</td>
  <td>2020-12-24 18:39:59</td>
  <td>Vendor</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>Category Table</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>Category</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>C</td>
  </tr>
  <tr>
  <td>2</td>
  <td>D</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>user_category table</strong></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Id</th>
  <th>user_id</th>
  <th>category_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>1</td>
  <td>1</td>
  </tr>
  <tr>
  <td>2</td>
  <td>1</td>
  <td>2</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Thank you in advance.</p>
  <p>p.s. sorry for my bad English.</p>