Adding new WHERE statements to a query in Laravel
<p>I'm doing a foreach loop in Laravel Eloquent where in each foreach I am in need of adding a new Where statement to a SQL query. I've tried this but it doesn't work:</p>

<pre><code>            $list = Records::whereNull('deleted_at');

            foreach ($search as $keyword) 
            {
                $list = $list-&gt;orWhere("title", 'like', '%'.$restriction.'%');
            }
            $list = $list-&gt;get();
</code></pre>

<p>This should then return:</p>

<pre><code>$list = Records::whereNull('deleted_at')-&gt;orWhere("title", 'like', '%'.$restriction[0].'%')-&gt;orWhere("title", 'like', '%'.$restriction[1].'%')-&gt;get();
</code></pre>

<p>But it just seems to return all records. Do note that I am only adding whereNull('deleted_at') in there because otherwise I have orWhere without having another where statement. </p>

<p>Is there a way to get this done?</p>