我目前在我的网站上有一个搜索功能,我需要它来搜索3个字段 - appid,mobilenumber,email。Laravel搜索多个字段
现在,用户在搜索框中输入数据后,它将搜索所有3个数据,但它不起作用。
使用GET收集数据。
这里是我的查询
http://www.example.com?id=1&searchall=07853637362
$mobile = INPUT::get('searchall');
$email = INPUT::get('searchall');
$appid = INPUT::get('searchall');
$data = DB::table('leads')
->when($mobile, function($query) use ($mobile){
return $query->where('MobilePhone', $mobile);
})
->when($email, function($query) use ($email){
return $query->where('Email', $email);
})
->when($appid, function($query) use ($appid){
return $query->where('AppID', $appid);
})
->get();
所以我需要它来搜索每个字段,直到找到正确的字段值。
考虑编写一些手动SQL不时,这会让你知道有OR子句的东西:) – Borjante