php - what is the alternative of insertGetId for multiple row insertion in laravel
Get the solution ↓↓↓I am inserting multiple rows in table, And I need to get both row id to insert another table, I was using this query for single row :
$ppfdata=[];
foreach($request->package_type_id as $ppfkey => $ppfno){
$ppfinput=[];
$ppfinput['paid_amount'] = $post_data['package_price'][$ppfkey];
$ppfinput['enroll_able'] = $post_data['enrollable'][$ppfkey];
$ppfinput['user_id'] = $post_data['user_id'];
$ppfinput['package_id'] = $post_data['package_id'][$ppfkey];
$ppfinput['plan_id'] = $post_data['plan_id'][$ppfkey];
$ppfinput['status'] = $post_data['status'][$ppfkey];
$ppfdata[]=$ppfinput;
}
$update_transections = DB::table('package_plan_fees')->insertGetId ($ppfdata);
What should I use for multiple rows ?
Answer
Solution:
You need to loop over the items. You can do this:
$ids = [];
foreach ($ppfdata as $item) {
$ids[] = DB::table('package_plan_fees')->insertGetId($item);
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: php_network_getaddresses: getaddrinfo failed: temporary failure in name resolution
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.