You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[11.x] Handle circular references in model serialization (#52461)
* [11.x] Added failing test for serializing circular relations
If a circular relationship is set up between two models using
`setRelation()` (or similar methods) then calling
`$model->relationsToArray()` will call `toArray()` on each related
model, which will in turn call `relationsToArray()`. In an instance
where one of the related models is an object that has already had
`toArray()` called further up the stack, it will infinitely recurse
down and result in a stack overflow.
The same issue exists with `getQueueableRelations()`, `push()`, and
potentially other methods. This adds tests which will fail if one of
the known potentially problematic methods gets into a recursive loop.
* [11.x] Added PreventsCircularRecursion
This adds a trait for Eloquent which can be used to prevent recursively
serializing circular references.
* [11.x] Changed the name to `withoutRecursion()`, accept a callable default
* formatting
* [11.x] Delay calling a "default" callback until the last possible second
* [11.x] Added additional tests for "callable" defaults
---------
Co-authored-by: Taylor Otwell <taylor@laravel.com>
0 commit comments