laravel/laravel — pull request #669 by awellis13 (2012-05-11 19:14:59+00:00)
Title: where_nested breaks on empty closures

I ran into an issue today where I needed to set conditions on my model's relationship ONLY if the search form I was using had a checkbox ticked.

The example code:

```
$results = MCache::with(array('spellings' => function($query) {
if (Input::get('flagged'))
{
$query->where('flagged', '=', '1')
}
}))->paginate(50);
```

This code above would break as if the condition isn't met that creates an empty `AND ()` statement in the query which breaks the query.

My fix will check to make sure `$query->wheres !== null` before adding to `$this->wheres`. This allows my above example to work as expected and I think should be default behavior in the query builder.