vendredi 1 novembre 2019

Return new collection without modifying original collection

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?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2WzXJ1C
via IFTTT

Aucun commentaire:

Enregistrer un commentaire