File tree Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,20 @@ foreach($user->reputations as $reputation) {
172172}
173173```  
174174
175+ If you want to get all the points given on a ` subject `  model. You should define a ` morphMany `  relations. For example on post model.
176+ 
177+ ``` php 
178+     /**
179+      * Get all the post's reputation.
180+      */
181+     public function reputations()
182+     {
183+         return $this->morphMany('QCod\Gamify\Reputation', 'subject');
184+     }
185+ ``` 
186+ 
187+ Now you can get all the reputation given on a ` Post `  using ` $post->reputations ` .
188+ 
175189### Configure a Point Type  
176190
177191#### Point payee  
Original file line number Diff line number Diff line change @@ -18,6 +18,16 @@ public function payee()
1818        return  $ this  ->belongsTo (config ('gamify.payee_model ' ), 'payee_id ' );
1919    }
2020
21+     /** 
22+      * Get the owning subject model 
23+      * 
24+      * @return \Illuminate\Database\Eloquent\Relations\MorphTo 
25+      */ 
26+     public  function  subject ()
27+     {
28+         return  $ this  ->morphTo ();
29+     }
30+ 
2131    /** 
2232     * Undo last point 
2333     * 
Original file line number Diff line number Diff line change @@ -25,4 +25,9 @@ public function bestReply()
2525    {
2626        return  $ this  ->hasOne (Reply::class, 'id ' , 'best_reply_id ' );
2727    }
28+ 
29+     public  function  reputations ()
30+     {
31+         return  $ this  ->morphMany ('QCod\Gamify\Reputation ' , 'subject ' );
32+     }
2833}
Original file line number Diff line number Diff line change @@ -69,6 +69,26 @@ public function it_gives_point_to_a_user()
6969        ]);
7070    }
7171
72+     /** 
73+      * it can access a reputation payee and subject 
74+      * 
75+      * @test 
76+      */ 
77+     public  function  it_can_access_a_reputation_payee_and_subject ()
78+     {
79+         $ user  = $ this  ->createUser ();
80+         $ post  = $ this  ->createPost (['user_id '  => $ user ->id ]);
81+ 
82+         $ user ->givePoint (new  FakeCreatePostPoint ($ post ));
83+ 
84+         $ point  = $ user ->reputations ()->first ();
85+ 
86+         $ this  ->assertEquals ($ user ->id , $ point ->payee ->id );
87+         $ this  ->assertEquals ($ post ->id , $ point ->subject ->id );
88+ 
89+         $ this  ->assertEquals ('FakeCreatePostPoint ' , $ post ->reputations ->first ()->name );
90+     }
91+ 
7292    /** 
7393     * it only adds unique point reward if property is set on point type 
7494     * 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments