我只想在這種特定情況下尋求幫助。因此,在我的應(yīng)用程序中,我們希望有一個全局搜索功能,您可以在其中放置 1 個字符串,然后我們必須使用 laravel eloquent 在數(shù)據(jù)庫中的多種情況下搜索該字符串,但是這已經(jīng)成為問題,因為我有多個 where has 然后我有withcount(我稍后會展示)。有人可以幫我解決這個問題嗎?將不勝感激這是代碼 $result = []; $sort_order = "DESC"; $post_param = $request->json()->all(); $filters = $post_param['filters']; if($post_param['sortOrder'] > 0) { $sort_order = "ASC"; } $financing_applications = $this->financing_application->model(); $data = $financing_applications::with('financing_application_data.business_type','financing_product_approval.financing_product')->withCount('financing_application_attachments as attachment'); foreach($filters as $key => $filter){ $value = $filter['value']; if($value != ""){ switch($key){ case "start_date_range": $data = $data->where('submission_date','>=',$value); break; case "end_date_range": $data = $data->where('submission_date','<=',$value); break; case "status": $data = $data->where($key,"LIKE","%$value%"); break; case "attachment_count": $data = $data->having('attachment_count','=',$value); break; case "company_name": case "telephone": }); } } }因此,在這種情況下,我的預(yù)期結(jié)果是能夠使用所有案例并將其組合到 switch 語句中的“全局”案例中。有沒有人有同樣的問題并有解決方案?上面的全局不起作用,因為 where 和 whereHas 應(yīng)該是 AND 不是 OR...我一直在尋找解決方案,但它太復(fù)雜了,我不知道這個問題的確切關(guān)鍵字這是您需要的一些信息"laravel/lumen-framework": "5.3.*"更新:如果你們中的一些人誤解了我的問題,我很抱歉,所以問題僅在于“全局”案例,現(xiàn)在與另一個案例在于“whereHas”語法來過濾關(guān)系。如果全局應(yīng)該能夠組合“Where”和“WhereHas”,我已經(jīng)做到了,但是因為沒有“orWhereHas”(據(jù)我所知),所以它將返回空,因為它被識別為“AND”語句
1 回答

神不在的星期二
TA貢獻(xiàn)1963條經(jīng)驗 獲得超6個贊
我找到了解決這個問題的方法,我必須用 has 替換 whereHas 語法,在這種情況下,它可以具有我需要的 OR 邏輯。
- 1 回答
- 0 關(guān)注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消