To merge two arrays together in Laravel, you can use the array_merge function. However, in this case, the two arrays have different structures, so you need to make sure that you merge them correctly.
In the provided code, $arrayForExcel is an array of associative arrays, while $differenceValuesForExcel is an array of arrays. To merge them together, you need to append each array in $differenceValuesForExcel to the corresponding array in $arrayForExcel.
Here's an updated version of the code that should work:
foreach ($cashRegisterRecords as $cashRegisterRecord) {
$arrayForExcel[] = [
'Konfirmuar nga punojesi' => $cashRegisterRecord->employee_name,
'Konfirmuar nga financa' => $cashRegisterRecord->finance_name,
'Tipi veprimit' => $cashRegisterRecord->type_of_action,
'Pershkrimi' => $cashRegisterRecord->description,
'Imazhi' => $cashRegisterRecord->image_path != null ? $cashRegisterRecord->image_path : '------',
'Vlera' => $this->getValues($cashRegisterRecord, $cashRegisterRecord->created_at),
'Vlera e vendosur nga punonjesi' => $this->getValuesInsertedFromEmployee($cashRegisterRecord, $cashRegisterRecord->created_at),
'Krijuar me' => Carbon::parse($cashRegisterRecord->created_at)->format('d-F-Y'),
'Ndryshuar me' => Carbon::parse($cashRegisterRecord->updated_at)->format('d-F-Y'),
];
$differenceValuesForExcel[] = $this->getDifferences($cashRegisterRecord, $allCurrencies);
}
// Merge the arrays
for ($i = 0; $i < count($arrayForExcel); $i++) {
$arrayForExcel[$i] = array_merge($arrayForExcel[$i], $differenceValuesForExcel[$i]);
}
return collect($arrayForExcel);
In this updated code, we first loop through $cashRegisterRecords and build $arrayForExcel and $differenceValuesForExcel as before. Then, we loop through $arrayForExcel and use array_merge to append each array in $differenceValuesForExcel to the corresponding array in $arrayForExcel.
Note that this assumes that $cashRegisterRecords, $arrayForExcel, and $differenceValuesForExcel all have the same number of elements. If that's not the case, you'll need to modify the code accordingly.