'Laravel, what can each() function do?

I have no specific work to do, just want to know what each() can do. I have googled, and saw this post: https://github.com/laravel/framework/issues/1380
It says

each is there to perform some operations on all items, that's all there is to it and that is what each is already doing.

What are the operations?



Solution 1:[1]

Take a look at the official laravel documentation: Laravel 5.4 Documentation

It states, that The each method iterates over the items in the collection and passes each item to a callback.

So for each item in the collection, it calls a function or does something. What that something is, is up to you to decide.

For example, the following snippet dumps every element in the collection:

$collection = $collection->each(function ($item, $key) {
    var_dump($item);
});

But you could also (for example) add it to a database or what ever comes to your mind.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 UeliDeSchwert