Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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从json数组获取DB表_Php_Mysql_Json_Laravel - Fatal编程技术网

Php 使用Laravel从json数组获取DB表

Php 使用Laravel从json数组获取DB表,php,mysql,json,laravel,Php,Mysql,Json,Laravel,我的数据库中有以下记录,我必须从中获取包含任何记录的所有记录 表记录包含: $record_id=[“123”、“234”、“111”] 尝试使用Laravel进行如下搜索: $records = DB::table('records_table') ->where('id', $id) ->whereRaw('JSON_CONTAINS(record_id, ?)', $record_ids) ->pluck('records'); 我也尝试过类似的解决方案,如

我的数据库中有以下记录,我必须从中获取包含任何记录的所有记录

表记录包含: $record_id=[“123”、“234”、“111”]

尝试使用Laravel进行如下搜索:

$records = DB::table('records_table')
  ->where('id', $id)
  ->whereRaw('JSON_CONTAINS(record_id, ?)', $record_ids)
  ->pluck('records');
我也尝试过类似的解决方案,如:

->whereIn('record_id', $record_ids)
我正在使用Laravel5.5和Mysql

更新: 当我“手动”添加它时,它会工作,如下所示:

->whereIn('record_id', ["123","234","111"])

但是当从数据库获取数组时,它不起作用

我想您应该在这里使用:

->whereIn('record_id', json_decode($json, true));

我想您应该在这里使用:

->whereIn('record_id', json_decode($json, true));
类型必须匹配(整数与字符串),搜索值必须是JSON编码的:

$search = json_encode(array_map('intval', $record_ids));

$records = DB::table('records_table')
    ->where('id', $id)
    ->whereRaw('JSON_CONTAINS(record_id, ?)', $search)
    ->pluck('records');
在Laravel 5.6中,您可以使用:

类型必须匹配(整数与字符串),搜索值必须是JSON编码的:

$search = json_encode(array_map('intval', $record_ids));

$records = DB::table('records_table')
    ->where('id', $id)
    ->whereRaw('JSON_CONTAINS(record_id, ?)', $search)
    ->pluck('records');
在Laravel 5.6中,您可以使用:


什么类型的列是
record\u id
?它是一个JSON表(也尝试过更改为文本)。JSON数组中的值是整数还是字符串?等等,对不起,我的错误!记录id是一个整数数组。您想查找
记录id
列包含
$record\u id
中所有id的行吗?记录id是什么类型的列?这是一个JSON表(也尝试更改为文本)。JSON数组中的值是整数还是字符串?等等,对不起,我的错误!记录id是一个整数数组您想查找
记录id
列包含
$record\u id
中所有id的行吗?是!成功了!我尝试了类似的方法,但问题出在上面的代码中,因此结果没有返回任何内容。是的!成功了!我尝试了类似的方法,但问题出在上面的代码中,因此结果没有返回任何内容。