Skip to content

Commit 33beb98

Browse files
committed
Wip
1 parent f16df2f commit 33beb98

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/Traits/ReviewRateable.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)