[5.4] add ability to define reloaded relationships #20602
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ran into this issue when using Laravel Echo to listen for some broadcast events.
currently when a Model is added to a queue and serialized, the
relationships of the Model are not restored when the Model is
unserialized/refetched from the database.
When you are handling the queued event/job with PHP, it’s not a big
issue. You can either manually load the relationships, or just use them
and they will be fetched when needed.
However, when you are broadcasting the events and listening for them in
Javascript, currently there is no way reload the relationship. This
addition allows us to define which relationships we would like to be
reloaded when the object is unserialized.
Simply add a
reloadedRelationships
property to your event or job:This will automatically reload the
user
andlines
relationships on the eventsorder
property.This syntax allows us to reload relationships on multiple models, if multiple models exist on the event/job.
I don't really love the name I came up with. Would love some suggestions on it.