我使用explode变量通过get方法获取值,但仅返回一个值
$part_id=explode(",",$request->input('part_id'));
$get_ltr = part::where('status',1)->where('part_no',$part_id)->get();
foreach($get_ltr as $key =>$value)
{
$ltr[$key] = $value['ltr'];
}
仅给我一个记录,我的代码中有什么问题,请帮助我
答案 0 :(得分:1)
您应该尝试以下操作:
$color_id=explode(",",$request->input('color_id'));
$part_id=explode(",",$request->input('part_id'));
$qty=explode(",",$request->input('qty'));
$qty_ltr = [30,15];
$get_ltr = part::where('status',1)->whereIn('part_no',$part_id)->get();
foreach($get_ltr as $key =>$value)
{
$ltr[$key] = $value['ltr'];
}
答案 1 :(得分:1)
看起来您应该使用whereIn()
。
$ids = explode(',', $request->input('part_id'));
$get_ltr = part::where('status',1)->whereIn('part_no', $ids)->get();
foreach($get_ltr as $key =>$value){
$ltr[$key] = $value['ltr'];
}