Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rakeshsoni18/064528d65f85a886e5ed7f4f9d438230 to your computer and use it in GitHub Desktop.
Save rakeshsoni18/064528d65f85a886e5ed7f4f9d438230 to your computer and use it in GitHub Desktop.
Add new column into the collections.
$collection = collect([
[
'price' => 2561,
'tax' => 50
],
[
'price' => 3500,
'tax' => 100
]
]);
return $collection->map(function ($items) {
$items['total_sum'] = $items['price'] + $items['tax'];
return $items;
});
===============================================================================
$collection = collect([
[
'price' => 2561,
'tax_percent' => 5
],
[
'price' => 3500,
'tax_percent' => 5
]
]);
return $collection->map(function ($items) {
$items['tax'] = $items['price'] * $items['tax_percent'] / 100;
$items['total_sum'] = $items['price'] + $items['tax'];
return $items;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment