關(guān)鍵字查詢,同時查詢兩個字段,一開始使用 orWhere寫法
$query->where('sms_title','like', '%'.$keywords.'%')
? ? ? ? ? ?->orWhere('sms_content','like', '%'.$keywords.'%');
如果只有這兩個條件,那就正常使用沒問題了.但是,這里還需要再加一個條件.
->where("sms.receiver_id", "=", $account_id)
這三條組合起來,結(jié)果就是我們想要的了.
于是找到下面的寫法:
$keywords = $arrData['keywords'] ;
if(!empty($keywords)){
? ? $query->where(DB::raw('concat(sms_title,sms_content)'),'like','%'.$keywords.'%');
}
問題完美解決!