Skip to content

[13.x] Ensure ScopedBy Attribute works with inheritance#59332

Merged
taylorotwell merged 1 commit intolaravel:13.xfrom
jackbayliss:13.x-ensure-scopedby-works-for-extend
Mar 23, 2026
Merged

[13.x] Ensure ScopedBy Attribute works with inheritance#59332
taylorotwell merged 1 commit intolaravel:13.xfrom
jackbayliss:13.x-ensure-scopedby-works-for-extend

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Mar 23, 2026

The ObservedBy attribute works with inheritance, but ScopedBy doesnt.

This PR fixes that.

This is a B/C, but arguably expected behavior IMO, if you did this the booted() way, it would work like this PR.

The code is pretty much a copy paste of what ObservedBy does no lie

Happy to target master, but thought I'd try 13.x first 🫡 Not sure if it needs porting back too

Example:

  class OrgModel extends Model
  {                                                                                                                                                                     
      protected static function booted(): void
      {                                                                                                                                                                 
          static::addGlobalScope(new OrgScope);                                                                                                              
      }
  }
  
  
  class Invoice extends OrgModel { // Has the right scope 
 
 #[ScopedBy(OrgScope::class)]
  class OrgModel extends Model {}
                                                                                                                                                                        
  class Invoice extends OrgModel { // Did not have the scope without this PR

@github-actions
Copy link

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss jackbayliss force-pushed the 13.x-ensure-scopedby-works-for-extend branch from 6c8a3cc to 166d52b Compare March 23, 2026 01:09
ensure it works with inheritence
@jackbayliss jackbayliss marked this pull request as ready for review March 23, 2026 08:46
@taylorotwell taylorotwell merged commit 96f9910 into laravel:13.x Mar 23, 2026
52 checks passed
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.

2 participants