Skip to content

Commit

Permalink
add documentation for attributesToArray (laravel#5215)
Browse files Browse the repository at this point in the history
`attributesToArray()` is a public method and is useful to avoid a potential infinite recursion if a model's relationships are not needed.  see https://stackoverflow.com/a/56400803/4468423
  • Loading branch information
epixian authored and taylorotwell committed Jun 1, 2019
1 parent fd946f7 commit cd16942
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions eloquent-serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ To convert a model and its loaded [relationships](/docs/{{version}}/eloquent-rel

return $user->toArray();

To convert only a model's attributes to an array, use the `attributesToArray` method:

$user = App\User::first();

return $user->attributesToArray();

You may also convert entire [collections](/docs/{{version}}/eloquent-collections) of models to arrays:

$users = App\User::all();
Expand Down

0 comments on commit cd16942

Please sign in to comment.