Level 58
You can use the array_merge() function to combine the arrays into one. Try the following code:
$currencies = CurrencyResource::collection(Currency::all());
$cashReceivedWithZeroValues = [];
foreach ($currencies as $currency){
$cashReceivedWithZeroValues[] = (object)[
'currency' => serialize([
$currency->name => '0',
]),
'date' => $dateRangeFormat
];
}
$cashReceivedWithZeroValues = array_merge(...$cashReceivedWithZeroValues);
return response()->json([
'message' => 'Success',
'data' => [
'allCurrencies' => $currencies,
'graphData' => OutlayResource::collection($cashReceivedWithZeroValues),
]
], 200);