laravel 5.5 使用whereIn的时候,参数加上变量无法返回结果
我在使用laravel 5.5框架的时候,在使用whereIn中加入获取的变量参数,无法正常返回结果,手动写成数值的时候正常返回。
使用变量:
$ids = '';
foreach ($menu as $v) {
if($user[0]['position']==$v['position_id']){
$ids .= $v['position_id'];
foreach ($v['child'] as $val) {
$ids .= ',' . $val['position_id'];
}
}
}
$page = $request->page ?: 1;
$pagesize = $request->pagesize ?: 10;
$data = $client->leftjoin('industry','client.industry','=','industry.industry_id')
->join('client_allot','client.client_id','=','client_allot.client_id')
->join('users','client_allot.user_id','=','users.id')
->select('client.client_id','company','tacpayer_type',DB::raw('concat(province,city,district) as area'),'industry_name','contact','client.creator','client.created_at')
->where('client_type', '=',2)
->where('allot_type', '=',1)
->whereIn('position',[$ids])
// ->orderBy(\DB::raw('FIND_IN_SET(position, "' . implode(",", [$ids]) . '"' . ")"))
->paginate($pagesize);
使用手动输入参数:
$data = $client->leftjoin('industry','client.industry','=','industry.industry_id')
->join('client_allot','client.client_id','=','client_allot.client_id')
->join('users','client_allot.user_id','=','users.id')
->select('client.client_id','company','tacpayer_type',DB::raw('concat(province,city,district) as area'),'industry_name','contact','client.creator','client.created_at')
->where('client_type', '=',2)
->where('allot_type', '=',1)
->whereIn('position',[4,5,6])
// ->orderBy(\DB::raw('FIND_IN_SET(position, "' . implode(",", [$ids]) . '"' . ")"))
->paginate($pagesize);
![手动输入数值]
我在网上和论坛上找不到任何信息,我自己也检查了几遍,无法找到问题源
推荐文章: