@@ -188,24 +188,52 @@ $product->getReviews(true, false);
188188$product->getReviews(withRatings: false);
189189```
190190### Fetch the average rating:
191- ```` php
192- // In progress
193- ````
194-
195- or
191+ ``` php
192+ // Retrieve a Product instance (assuming Product uses the ReviewRatable trait)
193+ $product = App\Models\Product::findOrFail($postId);
194+
195+ // Get the average rating for a specific key ('overall') using approved reviews (default).
196+ $overallAverage = $product->averageRating('overall');
197+ echo "Overall Average (approved): {$overallAverage}\n";
198+
199+ // Get the average rating for a specific key using non-approved reviews.
200+ $nonApprovedOverall = $product->averageRating('overall', false);
201+ echo "Overall Average (pending): {$nonApprovedOverall}\n";
202+
203+ // Get all average ratings for all rating keys from approved reviews.
204+ $allAverages = $product->averageRatings();
205+
206+ // Returns
207+ [
208+ "overall" => 3.5,
209+ "communication" => 2.75,
210+ "follow_up" => 3.5,
211+ "price" => 4.25
212+ ]
213+
214+ // Get the overall average rating across all ratings (approved reviews by default).
215+ $overallRating = $product->overallAverageRating();
216+ echo "Overall Rating Percentage: {$overallRating}%\n";
217+ ```
218+ ### Get all reviews with or without ratings:
219+ ``` php
220+ // Retrieve a Product instance (assuming Product uses the ReviewRatable trait)
221+ $product = App\Models\Product::find($postId);
196222
197- ```` php
198- // In progress
199- ````
223+ // Get all approved reviews with their ratings eager loaded.
224+ $reviewsWithRatings = $product->getReviews(true, true);
200225
201- ### Get all ratings:
202- ``` php
203- // In progress
226+ // Get all approved reviews without eager loading ratings.
227+ $reviewsWithoutRatings = $product->getReviews(true, false);
204228```
205229
206- ### Count total rating :
230+ ### Count total number of reviews :
207231```` php
208- // In progress
232+ // Retrieve a Product instance (assuming Product uses the ReviewRatable trait)
233+ $product = App\Models\Product::find($postId);
234+
235+ // Returns the total number of reviews.
236+ $totalReviews = $product->totalReviews();
209237````
210238
211239### Notes
0 commit comments