Laravel Eloquent where field is X or null
<p>I have a table like this:</p>

<pre><code>table
- field1: tinyint
- field2: varchar (nullable)
- datefield: timestamp (nullable)
</code></pre>

<p>Now I want to get all entries where field1 is 1, field2 is null and where datefield is smaller than X or null. I already tried something like this:</p>

<pre><code>$query = Model::where('field1', 1)
            -&gt;whereNull('field2')
            -&gt;where('datefield', '&lt;', $date)
            -&gt;orWhereNull('datefield');
</code></pre>

<p>but thats not working. I always get every entry where datefield is null. It doesn't matter what the other fields are. I also tried to split it in 2 queries: First get every row where datefield is smaller than X or null and then (based on it) get every field where field1 is 1 and field2 is null.</p>

<p>The result was the same.
Any idea how to do this?</p>