Skip to content

Commit de708a7

Browse files
committed
Added ability to get all reviews for a particular Model ID
1 parent 315e5a0 commit de708a7

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,21 @@ $post->deleteRating(1);
9292

9393
### Fetch the average rating:
9494
````php
95+
// Get Overall Average Rating
9596
$post->averageRating()
97+
98+
// Get Customer Service Average Rating
99+
$post->averageCustomerServiceRating()
100+
101+
// Get Quality Average Rating
102+
$post->averageQualityRating()
103+
104+
// Get Friendly Average Rating
105+
$post->averageFriendlyRating()
106+
107+
// Get Price Average Rating
108+
$post->averagePriceRating()
109+
96110
````
97111

98112
or

src/Contracts/ReviewRateable.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ public function rating($data, Model $author, Model $parent = null);
107107
*/
108108
public function updateRating($id, $data, Model $parent = null);
109109

110+
/**
111+
*
112+
* @param $id
113+
* @return mixed
114+
*/
115+
public function getRatings($id);
116+
110117
/**
111118
*
112119
* @param $id

src/Models/Rating.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ public function updateRating($id, $data)
6666
return $rating;
6767
}
6868

69+
/**
70+
* @param $id
71+
*
72+
* @return mixed
73+
*/
74+
public function getRatings($id)
75+
{
76+
$rating = $this->all()->where('reviewrateable_id', $id);
77+
78+
return $rating;
79+
}
80+
6981
/**
7082
* @param $id
7183
*

src/Traits/ReviewRateable.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ public function updateRating($id, $data, Model $parent = null)
206206
return (new Rating())->updateRating($id, $data);
207207
}
208208

209+
/**
210+
*
211+
* @param $id
212+
* @return mixed
213+
*/
214+
public function getRatings($id)
215+
{
216+
return (new Rating())->getRatings($id);
217+
}
218+
209219
/**
210220
* @param $id
211221
*

0 commit comments

Comments
 (0)