Reputation: 2051
Is there an elegant or proper way to extend Illuminate\Database\Eloquent
to modify the Collection that is returned?
For example, I have some code which needs to take some of the data for each model, and create a new property by looping through the data.
I prefer not to use a dynamic attribute for this, but maybe that's the cleanest way, as opposed to looping on the result after ->get()
is called and having to do this in a Controller.
Upvotes: 0
Views: 840
Reputation: 5174
I would recommend using as custom collection.
With that you can modify the collection, enrich it with your own methods and so on.
Upvotes: 1