Laravel eloquent multiple WHERE with OR AND OR and LIKE?

Laravelでこのようなクエリを作成しました(または作成しようとしています)。

問題は $orThose にあります。 LIKE`をクエリにしたい。

そのフィールドのデータは様々なものがありますが、フィールドには必ず"L3"や"ICU"などのキーワークが入っています。

このような場合に LIKE クエリを実行できますか?

$matchThese = ['link.hos_id' => $hos_id, 'outcome.otc_otrdischargedate' => $td];
$orThose = ['outcome.otc_outcome' => '@ICU@', 'outcome.otc_outcome' => '@I.C.U@'];

$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();
ソリューション

likenot likewhere()orWhere()メソッドで%` と共に使用します。

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

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

複数の AND を使用する場合は、次のようにします。

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

OR` を使用する場合は、次のようにします。

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

複数の ANDOR を組み合わせるには、パラメータのグループ化 を実行します。

->where('name', '=', 'John')
->orWhere(function ($query) {
    $query->where('votes', '>', 100)
          ->where('title', '', 'Admin');
})
解説 (2)

こんにちは 'or' と 'and#39 の両方の条件がある場合の参考文献をご覧ください。

テーブルストック

ここに画像の説明を入力1

$name='appl';
$type=1;
$stocks = DB::table('stocks')
            ->where('name', 'like', '%' . $name . '%')
            ->orWhere('company_name', 'like', '%' . $name . '%')
            ->where('exchange_id', '=', $type)
            ->get();
$results = json_decode($stocks, true);
print_r($results);
解説 (0)
public function searchData(Request $request)
{
  return Phonebook::where('name', 'like', '%'.$request->SearchQuery.'%')->orWhere('email', 'like', '%'.$request->SearchQuery.'%')->orWhere('phone', 'like', '%'.$request->SearchQuery.'%')->get();
}

ここでは、電話帳モデルから where, orwhere, like を使って、名前、メール、電話番号を検索しています。

解説 (0)