user2636197 user2636197 - 1 year ago 153
MySQL Question

Laravel optional where() query

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download