Last active
July 22, 2020 10:46
-
-
Save rakeshsoni18/064528d65f85a886e5ed7f4f9d438230 to your computer and use it in GitHub Desktop.
Add new column into the collections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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