[13.x] Support attribute inheritance for Broadcasting configuration in BroadcastsEvents#59583
Open
niduranga wants to merge 2 commits intolaravel:13.xfrom
Open
[13.x] Support attribute inheritance for Broadcasting configuration in BroadcastsEvents#59583niduranga wants to merge 2 commits intolaravel:13.xfrom
niduranga wants to merge 2 commits intolaravel:13.xfrom
Conversation
c0a483d to
9f51e7e
Compare
This commit introduces a new `BroadcastsEvents` attribute to allow defining broadcasting configuration (connection, queue, afterCommit) via attributes. It also updates the `BroadcastsEvents` trait to support attribute inheritance using `Reflector::getClassAttribute()`.
9f51e7e to
ba4091d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, models using the
BroadcastsEventstrait rely on class properties (e.g.,$broadcastConnection,$broadcastQueue) or methods to define their broadcasting configuration. While Laravel has introduced Attribute-based configurations for other Eloquent features, Broadcasting lacked a dedicated attribute.Furthermore, configuration defined on a
BaseModelwas not inherited by child models because the trait's reflection logic did not account for the inheritance chain.Proposed Changes
Illuminate\Database\Eloquent\Attributes\BroadcastsEventsto allow configuringconnection,queue, andafterCommitvia PHP 8 attributes.BroadcastsEventstrait to useReflector::getClassAttribute()withascend: true. This ensures that broadcasting settings defined on a parent class are automatically respected by all child models.static::classto ensure reliable reflection during the inheritance lookup.Benefits
#[ObservedBy]and#[ScopedBy].Example Usage
Testing
I have added an integration test in
DatabaseEloquentBroadcastingTest.phpto verify that:#[BroadcastsEvents]attribute is correctly resolved.ascendparameter.