【发布时间】:2021-08-13 15:17:23
【问题描述】:
我想在表中插入多行,我插入的数据集合具有唯一编号。例如:我为 user_id 编号 1 插入 2 行。我来自控制器的代码是:我想保留 DB::table() 而不是 laravel eloquent
foreach($post_data['user_id'] as $key => $no){
$set_base = DB::table('package_user')
->Insert([
'base_id' => $post_data['base_id'],
'base_title' => $post_data['base_title'],
'user_id' => $no,
'package_id' => $post_data['package_id'],
'plan_id' => $post_data['plan_id'],
'currency' => $post_data['currency'],
'payable_plan_amount' => $post_data['total_amount'],
'created_at' => Carbon::now()
]);
}
【问题讨论】: