Skip to content

Commit 89a201f

Browse files
authored
Merge pull request #9 from codebyray/develop
2 parents 14f38c9 + 2462761 commit 89a201f

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ $rating = $post->rating([
6565
'customer_service_rating' => 5,
6666
'quality_rating' => 5,
6767
'friendly_rating' => 5,
68-
'price_rating' => 5,
68+
'pricing_rating' => 5,
6969
'rating' => 5,
7070
'recommend' => 'Yes',
7171
'approved' => true, // This is optional and defaults to false
@@ -82,7 +82,7 @@ $rating = $post->updateRating(1, [
8282
'customer_service_rating' => 1,
8383
'quality_rating' => 1,
8484
'friendly_rating' => 3,
85-
'price_rating' => 4,
85+
'pricing_rating' => 4,
8686
'rating' => 4,
8787
'recommend' => 'No',
8888
'approved' => true, // This is optional and defaults to false
@@ -107,6 +107,11 @@ $ratings = $post->getNotApprovedRatings($post->id, 'desc');
107107

108108
// Get all ratings whether approved or not
109109
$ratings = $post->getAllRatings($post->id, 'desc');
110+
111+
// Get the most recent ratings (limit and sort are optional)
112+
// Limit default is 5, sort default is desc
113+
$ratings = $post->getRecentRatings($post->id, 5, 'desc');
114+
110115
```
111116
### Fetch the average rating:
112117
````php
@@ -123,7 +128,7 @@ $post->averageQualityRating()
123128
$post->averageFriendlyRating()
124129

125130
// Get Price Average Rating
126-
$post->averagePriceRating()
131+
$post->averagePricingRating()
127132

128133
````
129134

database/migrations/create_reviews_table.php.stub

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateReviewsTable extends Migration
1313
$table->integer('customer_service_rating')->nullable();
1414
$table->integer('quality_rating')->nullable();
1515
$table->integer('friendly_rating')->nullable();
16-
$table->integer('price_rating')->nullable();
16+
$table->integer('pricing_rating')->nullable();
1717
$table->enum('recommend', ['Yes', 'No']);
1818
$table->enum('department', ['Sales', 'Service', 'Parts']);
1919
$table->string('title');

src/Contracts/ReviewRateable.php

+8
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ public function getApprovedRatings($id, $sort = 'desc');
131131
*/
132132
public function getNotApprovedRatings($id, $sort = 'desc');
133133

134+
/**
135+
* @param $id
136+
* @param $limit
137+
* @param $sort
138+
* @return mixed
139+
*/
140+
public function getRecentRatings($id, $limit = 5, $sort = 'desc');
141+
134142
/**
135143
*
136144
* @param $id

src/Models/Rating.php

+18
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ public function getNotApprovedRatings($id, $sort = 'desc')
113113
return $rating;
114114
}
115115

116+
/**
117+
* @param $id
118+
* @param $limit
119+
* @param $sort
120+
* @return mixed
121+
*/
122+
public function getRecentRatings($id, $limit = 5, $sort = 'desc')
123+
{
124+
$rating = $this->select('*')
125+
->where('reviewrateable_id', $id)
126+
->where('approved', true)
127+
->orderBy('created_at', $sort)
128+
->limit($limit)
129+
->get();
130+
131+
return $rating;
132+
}
133+
116134
/**
117135
* @param $id
118136
*

src/Traits/ReviewRateable.php

+11
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ public function getNotApprovedRatings($id, $sort = 'desc')
239239
return (new Rating())->getNotApprovedRatings($id, $sort);
240240
}
241241

242+
/**
243+
* @param $id
244+
* @param $limit
245+
* @param $sort
246+
* @return mixed
247+
*/
248+
public function getRecentRatings($id, $limit = 5, $sort = 'desc')
249+
{
250+
return (new Rating())->getRecentRatings($id, $limit, $sort);
251+
}
252+
242253
/**
243254
* @param $id
244255
*

0 commit comments

Comments
 (0)