2016-09-20 30 views
2

我有(或想使)在LaravelLaravel雄辯的多個在哪裏與或和或像?

此查詢我的問題是與$orThose
我想查詢LIKE

該領域的數據可能很多,但總會有一些關鍵性的工作,如「L3」或「ICU」。

你能在這種情況下做一個LIKE查詢

$matchThese = ['link.hos_id' => $hos_id, 'outcome.otc_otrdischargedate' => $td]; 
$orThose = ['outcome.otc_outcome' => '@[email protected]', 'outcome.otc_outcome' => '@[email protected]']; 

$todaysReferrals = DB::table('link') 
->join('daily_link', 'link.lnk_id', '=', 'daily_link.dlk_lnkid') 
->join('demographic', 'link.lnk_dmgid', '=', 'demographic.dmg_id') 
->join('admission', 'link.lnk_admid', '=', 'admission.adm_id') 
->join('or_call', 'admission.adm_calid', '=', 'or_call.cal_id') 
->join('admission_score', 'admission.adm_scoreid', '=', 'admission_score.ascore_id') 
->join('diagnosis', 'link.lnk_dgnid', '=', 'diagnosis.dgn_id') 
->join('outcome', 'link.lnk_otcid', '=', 'outcome.otc_id') 
->where($matchThese) 
->orWhere($orThose) 
->get(); 

回答

3

使用likewhere()not like%orWhere()方法:

->where('column', 'like', '%pattern%') 

https://laravel.com/docs/5.3/queries#where-clauses

如果您需要使用多個AND做像這樣:

->where($condition) 
->where($anotherCondition) 

如果你想使用OR做到這一點:

->where($condition) 
->orWhere($anotherCondition) 

組合多個ANDORparameter grouping

->where('name', '=', 'John') 
->orWhere(function ($query) { 
    $query->where('votes', '>', 100) 
      ->where('title', '<>', 'Admin'); 
}) 
+0

你可以做一個'不作爲like'井?換一種說法。 '不包含這個短語'。我想像' - > where('title','<>','%Admin%')'可能會起作用 – morne

+0

當然,我已將它添加到答案中。你應該使用'不喜歡'運營商爲此。例如,' - > where('title','not like','%Admin%')' –

0
public function searchData(Request $request) 
{ 
    return Phonebook::where('name', 'like', '%'.$request->SearchQuery.'%')->orWhere('email', 'like', '%'.$request->SearchQuery.'%')->orWhere('phone', 'like', '%'.$request->SearchQuery.'%')->get(); 
} 

這裏,我已經找遍姓名,電話號碼和電話號碼德爾使用其中orwhere