Answer the question
In order to leave comments, you need to log in
Why is a collection needed?
Do I need to wrap the array when outputting to the front of the collection? And in general, why do we need a collection if working with an array is already using approximately the same methods as with a collection?
I just read the documentation and did not understand why to use it if you can just work directly with an array
Answer the question
In order to leave comments, you need to log in
since version 5.3 you can just return what you have. Any format in api routes is converted to json
if you have Laravel 5.3 or higher, you don’t have to worry
Collections are more convenient, IMHO.
For example, it is more convenient for me to use the each method of the collection than foreach.
Also with sorting, filtering, all actions can be laid out readably.
$collection
->filter()
->sort()
->each();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question