WHERE clause with AND OR in Laravel 5.1?

2020-03-08 07:49发布

问题:

i am trying to use Where clause in Laravel 5.1 with or And or conditions, here is my requirement:

->WHERE (request_id=1) and (sender_id=11 or receiver_id=11)

how to use the above clause in Laravel 5.

Your help would be really appreciated :)

回答1:

DB::table('yourTable')
        ->where('request_id', '=', '1')
        ->where(function($query)
        {
            $query->where('sender_id', '=', 11)
                  ->orWhere('receiver_id', '=', '11');
        })
        ->get();