Reputation: 713
Can someone explain the difference between $model->attributesToArray()
and $model->toArray()
on a model?
I have an issue where a seeder is throwing an error about getCreatedAtAttribute
method is not defined and it's complaining due to a toArray()
method call. This is what prompted me to try and find out the difference between the two.
After switching to attributesToArray()
the seeder runs fine.
Upvotes: 4
Views: 4216
Reputation: 33196
attributesToArray
will only fetch the attributes for the current model.
toArray
calls the attributesToArray
function, but also adds loaded relations to the array.
Upvotes: 10