File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
src/Illuminate/Database/Eloquent/Concerns Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 44
55use Closure ;
66use Illuminate \Database \Eloquent \Attributes \ScopedBy ;
7+ use Illuminate \Database \Eloquent \Model ;
78use Illuminate \Database \Eloquent \Scope ;
89use Illuminate \Support \Arr ;
910use Illuminate \Support \Collection ;
@@ -38,8 +39,15 @@ public static function resolveGlobalScopeAttributes()
3839 $ attributes ->push (...$ trait ->getAttributes (ScopedBy::class, ReflectionAttribute::IS_INSTANCEOF ));
3940 }
4041
42+ $ isEloquentGrandchild = is_subclass_of (static ::class, Model::class)
43+ && get_parent_class (static ::class) !== Model::class;
44+
4145 return $ attributes ->map (fn ($ attribute ) => $ attribute ->getArguments ())
4246 ->flatten ()
47+ ->when ($ isEloquentGrandchild , function (Collection $ attributes ) {
48+ return (new Collection (get_parent_class (static ::class)::resolveGlobalScopeAttributes ()))
49+ ->merge ($ attributes );
50+ })
4351 ->all ();
4452 }
4553
Original file line number Diff line number Diff line change @@ -68,6 +68,14 @@ public function testGlobalScopeInInheritedAttributeIsApplied()
6868 $ this ->assertEquals ([1 ], $ query ->getBindings ());
6969 }
7070
71+ public function testGlobalScopeInParentClassAttributeIsApplied ()
72+ {
73+ $ model = new EloquentGlobalScopeInAttributeChildTestModel ;
74+ $ query = $ model ->newQuery ();
75+ $ this ->assertSame ('select * from "table" where "active" = ? ' , $ query ->toSql ());
76+ $ this ->assertEquals ([1 ], $ query ->getBindings ());
77+ }
78+
7179 public function testClosureGlobalScopeIsApplied ()
7280 {
7381 $ model = new EloquentClosureGlobalScopesTestModel ;
@@ -325,3 +333,14 @@ class EloquentGlobalScopeInInheritedAttributeTestModel extends Model
325333
326334 protected $ table = 'table ' ;
327335}
336+
337+ #[ScopedBy(ActiveScope::class)]
338+ class EloquentGlobalScopeInAttributeParentTestModel extends Model
339+ {
340+ protected $ table = 'table ' ;
341+ }
342+
343+ class EloquentGlobalScopeInAttributeChildTestModel extends EloquentGlobalScopeInAttributeParentTestModel
344+ {
345+ //
346+ }
You can’t perform that action at this time.
0 commit comments