Laravel 5.2 whereRaw with muliple where条件

时间:2016-11-16 17:29:13

标签: php eloquent laravel-5.2

下面是我的查询。我希望得到所有结果如果(尼克或移动)和课程匹配,

请咨询

        $conversations = Inquiries::whereRaw("( `course` = $request->input('course'))
            AND( `mobile` = $request->input('mobile') OR 'nic', 'LIKE', '%'.$request->input('nic').'%')")
            ->get();

1 个答案:

答案 0 :(得分:1)

您需要正确创建一个查询,如下所示:

$conversations = Inquiries::where('course', '=', $request->input('course'))
    ->where(function($query) use ($request) {
        $query->where('mobile','=', $request->input('mobile'))
            ->orWhere('nic','LIKE','%'.$request->input('nic').'%');
    })
    ->get();