Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将数据数组检查到laravel中的where条件?_Php_Laravel - Fatal编程技术网

Php 如何将数据数组检查到laravel中的where条件?

Php 如何将数据数组检查到laravel中的where条件?,php,laravel,Php,Laravel,我有一个来自视图的book[]输入字段 $arr = $request->book_name; dd($arr); dd结果如下 array:2 [ 0 => "1" 1 => "3" ] 我想从library表中选择数据,其中book\u id与上面的数组匹配,我编写了下面的查询,但它给出了如下错误: 类型错误:参数1传递给 Illumb\Database\Grammar::parameterize()必须为以下

我有一个来自视图的
book[]
输入字段

 $arr = $request->book_name;
 dd($arr);
dd
结果如下

array:2 [
    0 => "1"
    1 => "3"
]
我想从
library
表中选择数据,其中
book\u id
与上面的数组匹配,我编写了下面的查询,但它给出了如下错误:

类型错误:参数1传递给 Illumb\Database\Grammar::parameterize()必须为以下类型 数组,给定字符串,在D中调用

查询如下:

$libQuantity = \DB::table('library')->select('quantity')->whereIn('book_id', '=', $arr)->get();
尝试:

问题是

'book\u id'、'='、$arr
应该是
'book\u id'、$arr

试试:

问题是


'book\u id'、'='、$arr
应该是
'book\u id'、$arr

有库模型吗?有
模型有库模型吗?有
模型哈!我不敢相信这仅仅是因为
=
,谢谢你,兄弟,它成功了。哈哈!我不敢相信这仅仅是因为
=
,谢谢你,兄弟,它成功了。
$libQuantity = \DB::table('library')
                    ->select('quantity')
                    ->whereIn('book_id', $arr)
                    ->get();

$libQuantity = \App\Models\Library::whereIn('book_id', $arr)
                    ->get(['library']);