Skip to content

Commit cdc271d

Browse files
committed
Updated docs.
1 parent d87a108 commit cdc271d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ class Product extends Model
112112
use ReviewRateable;
113113
}
114114
```
115-
### Adding a Review
115+
### Adding a review/rating(s)
116116
You can add a review (with ratings) directly via the trait:
117117
```php
118-
$product = Product::find(1);
118+
$product = Product::find($productId);
119119

120120
$product->addReview([
121121
'review' => 'Great product! The quality is superb and customer service was excellent.',
@@ -131,10 +131,10 @@ $product->addReview([
131131
], auth()->id());
132132
```
133133

134-
### Update a rating
134+
### Update a review/rating(s)
135135
```php
136136
// Retrieve the product you want to update the review for.
137-
$product = Product::findOrFail(1);
137+
$product = Product::findOrFail($productId);
138138

139139
// Prepare the updated data.
140140
$data = [
@@ -156,7 +156,7 @@ $product->updateReview($reviewId, $data);
156156
### Marking review as approved
157157
```php
158158
// Retrieve the product you want to mark as approved
159-
$product = Product::findOrFail(1);
159+
$product = Product::findOrFail($productId);
160160

161161
// Approve th review
162162
$product->approveReview($reviewId);
@@ -173,7 +173,7 @@ $product->deleteReview($reviewId);
173173
### Fetch approved or not approved reviews/ratings for a particular resource
174174
```php
175175
// Approved reviews with ratings
176-
$product = Product::findOrFail($postId);
176+
$product = Product::findOrFail($productId);
177177

178178
// Get approved reviews (with related ratings)
179179
// Default: approved = true, withRatings = true
@@ -190,7 +190,7 @@ $product->getReviews(withRatings: false);
190190
### Fetch the average rating:
191191
```php
192192
// Retrieve a Product instance (assuming Product uses the ReviewRatable trait)
193-
$product = App\Models\Product::findOrFail($postId);
193+
$product = Product::findOrFail($productId);
194194

195195
// Get the average rating for a specific key ('overall') using approved reviews (default).
196196
$overallAverage = $product->averageRating('overall');
@@ -203,7 +203,7 @@ echo "Overall Average (pending): {$nonApprovedOverall}\n";
203203
// Get all average ratings for all rating keys from approved reviews.
204204
$allAverages = $product->averageRatings();
205205

206-
// Returns
206+
// Returns something like
207207
[
208208
"overall" => 3.5,
209209
"communication" => 2.75,
@@ -213,12 +213,14 @@ $allAverages = $product->averageRatings();
213213

214214
// Get the overall average rating across all ratings (approved reviews by default).
215215
$overallRating = $product->overallAverageRating();
216-
echo "Overall Rating Percentage: {$overallRating}%\n";
216+
217+
// Returns float
218+
3.5
217219
```
218220
### Get all reviews with or without ratings:
219221
```php
220222
// Retrieve a Product instance (assuming Product uses the ReviewRatable trait)
221-
$product = App\Models\Product::find($postId);
223+
$product = Product::find($productId);
222224

223225
// Get all approved reviews with their ratings eager loaded.
224226
$reviewsWithRatings = $product->getReviews(true, true);
@@ -230,7 +232,7 @@ $reviewsWithoutRatings = $product->getReviews(true, false);
230232
### Count total number of reviews:
231233
````php
232234
// Retrieve a Product instance (assuming Product uses the ReviewRatable trait)
233-
$product = App\Models\Product::find($postId);
235+
$product = Product::find($productId);
234236

235237
// Returns the total number of reviews.
236238
$totalReviews = $product->totalReviews();

0 commit comments

Comments
 (0)