title: Laravel eloquent relation search using child table record
body: <p><strong>Problem :</strong> </p>
  
  <p>I want only that records where relational records [ <code>user</code> ] not null.</p>
  
  <p>In my case <strong>I want only first record</strong>. where <code>user</code> is not null</p>
  
  <p>Result:
  <img src="https://i.stack.imgur.com/FGaKu.png" alt="enter image description here"></p>
  
  <p><strong>User Table</strong> </p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  <li>email</li>
  </ul>
  
  <p><strong>Project Tabel</strong></p>
  
  <ul>
  <li>id</li>
  <li>title</li>
  <li>user_id <code>[foreign key]</code></li>
  </ul>
  
  <p>My code is like this</p>
  
  <pre><code>$projects = App\Project::with(['user' =&gt; function ($user) {
                      $user-&gt;where('name', '=', 'Ketan');
                  }])
                  -&gt;get();
  
  foreach ($projects as $project) {
      echo $project-&gt;title.' - '.$project;
  }
  </code></pre>
  
  <p>My result is like this : 
  <img src="https://i.stack.imgur.com/FGaKu.png" alt="enter image description here"></p>