File tree Expand file tree Collapse file tree 5 files changed +55
-1
lines changed Expand file tree Collapse file tree 5 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 66use  Illuminate \Database \Eloquent \Model ;
77use  Illuminate \Database \Eloquent \Relations \MorphTo ;
88use  Tobyz \JsonApiServer \Context ;
9+ use  Tobyz \JsonApiServer \Laravel \Field \ToMany ;
10+ use  Tobyz \JsonApiServer \Laravel \Field \ToOne ;
911use  Tobyz \JsonApiServer \Schema \Field \Relationship ;
1012
1113abstract  class  EloquentBuffer
@@ -56,7 +58,21 @@ public static function load(
5658                    $ modelClassget_class ($ resourcenewModel ($ context
5759
5860                    if  ($ resourceinstanceof  EloquentResource && !isset ($ constrain$ modelClass
59-                         $ constrain$ modelClassfn ($ query$ resourcescope ($ query$ context
61+                         $ constrain$ modelClassfunction  ($ queryuse  (
62+                             $ resource
63+                             $ context
64+                             $ relationship
65+                         ) {
66+                             $ resourcescope ($ query$ context
67+ 
68+                             if  (
69+                                 ($ relationshipinstanceof  ToMany ||
70+                                     $ relationshipinstanceof  ToOne) &&
71+                                 $ relationshipscope 
72+                             ) {
73+                                 ($ relationshipscope )($ query$ context
74+                             }
75+                         };
6076                    }
6177                }
6278
Original file line number Diff line number Diff line change 1+ <?php 
2+ 
3+ namespace  Tobyz \JsonApiServer \Laravel \Field \Concerns ;
4+ 
5+ use  Closure ;
6+ 
7+ trait  ScopesRelationship
8+ {
9+     public  ?Closure $ scopenull ;
10+ 
11+     public  function  scope (?Closure $ scopestatic 
12+     {
13+         $ this scope  = $ scope
14+ 
15+         return  $ this 
16+     }
17+ }
Original file line number Diff line number Diff line change 1+ <?php 
2+ 
3+ namespace  Tobyz \JsonApiServer \Laravel \Field ;
4+ 
5+ use  Tobyz \JsonApiServer \Schema \Field \ToMany  as  BaseToMany ;
6+ 
7+ class  ToMany extends  BaseToMany
8+ {
9+     use  Concerns \ScopesRelationship;
10+ }
Original file line number Diff line number Diff line change 1+ <?php 
2+ 
3+ namespace  Tobyz \JsonApiServer \Laravel \Field ;
4+ 
5+ use  Tobyz \JsonApiServer \Schema \Field \ToOne  as  BaseToOne ;
6+ 
7+ class  ToOne extends  BaseToOne
8+ {
9+     use  Concerns \ScopesRelationship;
10+ }
Original file line number Diff line number Diff line change 22
33namespace  Tobyz \JsonApiServer \Schema \Field ;
44
5+ use  Closure ;
56use  Tobyz \JsonApiServer \Context ;
67use  Tobyz \JsonApiServer \Exception \BadRequestException ;
78use  Tobyz \JsonApiServer \Exception \Sourceable ;
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments