t0berius's avatar

laravel collection add item to each entry "on the fly"

The following collection contains Order models. How can I add an entry "on the fly" so it won't only exist inside the collection itself?

        $orders->map(function ($order) use ($externalHelper) {
            $order['new_field'] =  "some_new_data_added_on_the_fly";
            return $order;
        });

Using this code, the new data isn't added to the collection when I run dd($orders);.

0 likes
2 replies

Please or to participate in this conversation.