I have a Laravel collection and I want to modify one of its property value to negative integer. For this I am using map function on collection but it also modifying the original collection.
Here is my code
$modified_revenue_data = $revenue_data->map(function ($item) {
if ($item->is_claw_back == 1 && $item->claw_back_date != null)
{
return $item->revenue = $item->revenue * -1;
}
return $item;
});
I want to store new collection into $modified_revenue_data
but $revenue_data
also being modified.
What is the correct way of doing it without changing anything from original collection?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire