user2636197 - 11 months ago 108

MySQL Question

I wonder if there is something like a optional where query. Eg:

Select * from table where X must be = 2 and Y must be equal to 0 or 1?

Answer Source

You may try as:

```
$userId = $request->input('userId');
->where('X', 2)
->where(function($q) use($userId) {
$q->where('Y', $userId)
->orWhere('Y', 1)
})
```