title: Laravel - Search relation including null in whereHas
body: <p>I'm trying to find a way to search the relationship.</p>
  
  <p>So, I have one to one relation (User and UserDetails, where some of the user can be without details).</p>
  
  <p>So, the question is... how can I search Users by their details, but also Users without details must be included into the results.</p>
  
  <p>Example:
  Table users:
  user_id, name, email
  - 1 John Doe johndoe@address.com
  - 2 Richard Tim richardtim@address.com
  - 3 Michael Bird michaelbird@address.com</p>
  
  <p>Table user_details:
  ID, user_id, state
  - 1, 1, California
  - 2, 2, New York</p>
  
  <p>and now... I want to get all users from California, and all users without state (In above case results should be John Doe and Michael Bird</p>
  
  <p>Here is relation in User model:</p>
  
  <pre><code>public function details()
  {
      return $this-&gt;belongsTo('App\UserDetails', 'user_id', 'user_id');
  }
  </code></pre>
  
  <p>and search function is:</p>
  
  <pre><code>$users = $users-&gt;whereHas('details', function($query) use $state {
      $query-&gt;where('state', $state);
  });
  </code></pre>
  
  <p><strong>Keep in mind that I must to do that using instance of eloquent / query builder, I'm not able to use joins or raw queries.</strong></p>
  
  <p>In this case, I want to get all users from California and all non-related users, but the query returns/search only related users/user_details...</p>
  
  <p>So, can someone to help me ?
  Thanks</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I'm trying like that:</p>
  
  <pre><code>$users = new User();
  $users = $users-&gt;doesntHave('user_details')-&gt;orWhereHas('user_details', function($query) use($state) {
                  $query-&gt;whereIn('state', $state);
              });
  $users-&gt;where('created_at', '&gt;=', $start_date);
  $users-&gt;where('created_at', '&lt;=', $end_date);
  </code></pre>