【发布时间】:2017-06-06 07:47:07
【问题描述】:
我在我的控制器中使用 jquery 获取 ids
if(!empty($request->input('ids'))) {
$ids = $request->input('ids');
}else{
$ids = null;
}
我试试dd($ids)
输出和我的控制台一样
array:3 [
0 => "1"
1 => "2"
2 => "on"
]
当我将 ids 传递给我的查询时
查询
$student_ids = DB::table('students')
->orderBy('name', 'asc')
->where('group_id', '<>', 0)
->whereIn('students.id','=', $ids)
->pluck('id');
它不工作
错误是:为 foreach 提供的参数无效
请帮助我哪里错了。谢谢
【问题讨论】:
-
如何在视图中获取 id? 3.数组“on”中的元素应该存在吗?我认为那里有问题。
-
为什么你的 id 是字符串?
-
if($request->has('ids'))) {}
-
你的 foreach 实际上在哪里?
-
->whereIn('students.id', $ids) - 更多信息请查看laravel.com/docs/5.4/queries