File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,25 @@ public function ratingTypes(): array
1717 return config ('reviewrateable.default_rating_types ' );
1818 }
1919
20- public function addReview ($ data )
21- {
22- $ data ['approved ' ] = config ('reviewrateable.default_approved ' , false );
20+ public function addReview ($ data , $ author )
21+ {
22+ // Separate ratings from other data
23+ $ ratings = [];
24+ foreach ($ this ->ratingTypes () as $ type ) {
25+ if (isset ($ data ["{$ type }_rating " ])) {
26+ $ ratings [$ type ] = $ data ["{$ type }_rating " ];
27+ unset($ data ["{$ type }_rating " ]);
28+ }
29+ }
30+ $ data ['ratings ' ] = $ ratings ;
31+
32+ // Create review
33+ $ data ['author_id ' ] = $ author ->id ;
34+ $ data ['author_type ' ] = get_class ($ author );
35+ $ data ['approved ' ] = $ data ['approved ' ] ?? config ('review-rateable.default_approved ' , false );
2336 $ review = new Review ($ data );
2437 $ this ->reviews ()->save ($ review );
38+
2539 return $ review ;
2640 }
2741
You can’t perform that action at this time.
0 commit comments