我尝试过有条件。
$CustomerData = Customer::orderBy('_id', 'desc');
$CustomerData = $CustomerData
->where('first_name', 'like', '%' . $search . '%')
->orWhere('middle_name', 'like', '%' . $search . '%')
->with('addressData')
->whereHas('addressData',
function($query) use ($search)
{
$query->orWhere('country', 'like', '%' . $search . '%');
$query->orWhere('state', 'like', '%' . $search . '%');
});
答案 0 :(得分:0)
@Vishal检查以下示例代码以在不同的表之间进行搜索:
此处的代码:
public function SimpleSearch($term)
{
$match = "MATCH(authors.authors) AGAINST(? IN BOOLEAN MODE)";
$match1 = "MATCH(keywords.keywords) AGAINST(? IN BOOLEAN MODE)";
$match2 = "MATCH(research_papers.title) AGAINST(? IN BOOLEAN MODE)";
$match3 = "MATCH(research_papers.abstract) AGAINST(? IN BOOLEAN MODE)";
$researchpapers = DB::table('keywords')
->join('research_papers','keywords.researchpaper_id','=','research_papers.id')
->join('authors','authors.researchpaper_id','=','research_papers.id')
->leftjoin('favorite_models','favorite_models.researchpaper_id','=','research_papers.id')
->whereRaw($match1,array($term))
->orwhereRaw($match2,array($term))
->orwhereRaw($match3,array($term))
->orwhereRaw($match,array($term))
->orderbyRaw($match2."DESC",array($term))
->orderby('dates','desc')
->select('research_papers.id','research_papers.title','research_papers.dates','research_papers.abstract','research_papers.paperlinks','authors.authors','keywords.keywords','research_papers.doi','favorite_models.researchpaper_id','research_papers.websites')
->paginate(10);
return $researchpapers;
}
我希望这会有所帮助。它对我有用。