Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

Collections are a new feature of Laravel 4. You can certainly do without them but in certain cases they can really cut down the amount of code you need to write when you need to work with a set of records.

To understand the benefits I recommend you check out Dayle Rees' Code Bright chapter on Collections: http://daylerees.com/codebright/eloquent-collections

Maybe someone else has more input.

Last updated 2 years ago.
0

thanks for that - yup, Dayle has done a good job of explaining what they are, I have his book and have read the section in Collections. I can see that they could cut down code, but they appear to add some complexity.

It would be brilliant if some one could explain the benefit of using them.

Last updated 2 years ago.
0

Collections have nothing to do with sql queries. They are just a container for data. It just so happens that eloquent (which does have something to do with sql) uses collections to store the result sets.

You can look at Collections as a fancy replacement for arrays. Look at the Collection class in the code to see what functionality collections give you.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

vincej vincej Joined 10 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.