I have an array of 3 companies, which need to be inserted into the db but with 2 additional parameters added to them.
$companyList = [{"name": "apple", "founder": "steve"},
{"name": "google", "founder": "larry"},
{"name": "facebook", "founder": "mark"},
];
Need to append these 2 parameters for each company (issue is in this step):
$companyListFinal = [];
foreach ($companyList as $company) {
$companyListFinal[] = array_add($company,['keyAppend1' => 'key 1 appended',
'keyAppend2' => 'key 2 appended'];
}
The final step is to insert the company list with the appended values into the DB:
DB::table('companies')->insert($companyListFinal);
I can't seem to be able to append the 2 new parameters to create the final array to insert:$companyListFinal
What's the correct way to add the parameters to each company so they are all inserted at bulk?