Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add a hook to the serialisation of collections #44272

Merged
merged 4 commits into from
Sep 23, 2022

Conversation

Smoggert
Copy link
Contributor

This allows the use of parent/child Models in the same collection, to be properly serialized using the parent model (given a proper trait that facilitates the new function provided).

Parent/child models as implemented in for example (https://github.com/calebporzio/parental) currently cause serialization errors when attempting to queue or otherwise serialize a collection containing them.

This hook would allow us to alleviate the issue.

If rather than checking for the existence of the function you'd rather just call the function, it can also easily be implemented on the model by default and then overwritten by the trait.

Smoggert and others added 4 commits September 23, 2022 14:25

Verified

This commit was signed with the committer’s verified signature.
serhalp Philippe Serhal
This allows the use of parent/child Models in the same collection, to be properly serialized using the parent model (given a proper trait that facilitates the new function).
Parent/child models as implemented in for example (https://github.com/calebporzio/parental) currently cause serialization errors when attempting to queue or otherwise serialize a collection containing them. 

This hook would allow us to alleviate the issue.

Verified

This commit was signed with the committer’s verified signature.
serhalp Philippe Serhal
…sname-hook

Allow hooking the queueable collection logic
@taylorotwell taylorotwell merged commit e7d534e into laravel:9.x Sep 23, 2022
Smoggert added a commit to Smoggert/parental that referenced this pull request Sep 26, 2022
Update HasParent.php to fix collection serialization.

Currently Parental creates unserializable Eloquent collections resulting in an error when pushing the colleciton to queue

Queueing collections with multiple model types is not supported.

I merged a framework request to create this callback on the model to circumvent the issue.
laravel/framework#44272

This should fix the serialization error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants