We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
I recently submitted a pull request to the Laravel framework to add a new Eloquent attribute called
CollectedBy
. In short, it allows you to use an attribute to configure your Eloquent model to use a specific Collection class, rather than the default (which isIlluminate\Database\Eloquent\Collection
).Just to mention it: the concept of using custom collections is nothing new. You've been able to do that for a while by overriding the model's
newCollection
method. All the attribute does is let you configure the collection class to use in a more declarative way, but hopefully this may make it a bit more approachable.As the PR was merged and I saw some questions popping up over at X, I figured I should write a few lines about the benefits (and drawbacks!) of using custom collections.
continue reading on alsterholm.com
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.