laravel下载数据关联模型数据多超出mysql占位数?

1、查询用户列表,初始换关联订单表,但是用户太多,导致mysql占位符过了,报mysql错误。

2、User::with('order')->get()

报错:General error: 1390 Prepared statement contains too many placeholders

select * from order where user_id in (xxx,xxx , ......)
因为后续需要循环处理订单相关联的数据。
foreach ($user as $v) {

$order_list = $v->order;
$temp_test = [];
if (count($order_list) > 0) {
    foreach ($order_list as $ov) {
        $temp_test[] = $ov->order_id;
    }
}
$data = [
    'user_id' => $v->user_id,
    'order_id' => implod(',', $temp_test)
];
echo $this->downExcel($data);

}

梵蒂冈之花
浏览 315回答 1
1回答

万千封印

使用chunk即可。
打开App,查看更多内容
随时随地看视频慕课网APP