Skip to content

Commit

Permalink
Merge pull request #9 from codebyray/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
codebyray authored Oct 18, 2019
2 parents 14f38c9 + 2462761 commit 89a201f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ $rating = $post->rating([
'customer_service_rating' => 5,
'quality_rating' => 5,
'friendly_rating' => 5,
'price_rating' => 5,
'pricing_rating' => 5,
'rating' => 5,
'recommend' => 'Yes',
'approved' => true, // This is optional and defaults to false
Expand All @@ -82,7 +82,7 @@ $rating = $post->updateRating(1, [
'customer_service_rating' => 1,
'quality_rating' => 1,
'friendly_rating' => 3,
'price_rating' => 4,
'pricing_rating' => 4,
'rating' => 4,
'recommend' => 'No',
'approved' => true, // This is optional and defaults to false
Expand All @@ -107,6 +107,11 @@ $ratings = $post->getNotApprovedRatings($post->id, 'desc');

// Get all ratings whether approved or not
$ratings = $post->getAllRatings($post->id, 'desc');

// Get the most recent ratings (limit and sort are optional)
// Limit default is 5, sort default is desc
$ratings = $post->getRecentRatings($post->id, 5, 'desc');

```
### Fetch the average rating:
````php
Expand All @@ -123,7 +128,7 @@ $post->averageQualityRating()
$post->averageFriendlyRating()

// Get Price Average Rating
$post->averagePriceRating()
$post->averagePricingRating()

````

Expand Down
2 changes: 1 addition & 1 deletion database/migrations/create_reviews_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CreateReviewsTable extends Migration
$table->integer('customer_service_rating')->nullable();
$table->integer('quality_rating')->nullable();
$table->integer('friendly_rating')->nullable();
$table->integer('price_rating')->nullable();
$table->integer('pricing_rating')->nullable();
$table->enum('recommend', ['Yes', 'No']);
$table->enum('department', ['Sales', 'Service', 'Parts']);
$table->string('title');
Expand Down
8 changes: 8 additions & 0 deletions src/Contracts/ReviewRateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ public function getApprovedRatings($id, $sort = 'desc');
*/
public function getNotApprovedRatings($id, $sort = 'desc');

/**
* @param $id
* @param $limit
* @param $sort
* @return mixed
*/
public function getRecentRatings($id, $limit = 5, $sort = 'desc');

/**
*
* @param $id
Expand Down
18 changes: 18 additions & 0 deletions src/Models/Rating.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ public function getNotApprovedRatings($id, $sort = 'desc')
return $rating;
}

/**
* @param $id
* @param $limit
* @param $sort
* @return mixed
*/
public function getRecentRatings($id, $limit = 5, $sort = 'desc')
{
$rating = $this->select('*')
->where('reviewrateable_id', $id)
->where('approved', true)
->orderBy('created_at', $sort)
->limit($limit)
->get();

return $rating;
}

/**
* @param $id
*
Expand Down
11 changes: 11 additions & 0 deletions src/Traits/ReviewRateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ public function getNotApprovedRatings($id, $sort = 'desc')
return (new Rating())->getNotApprovedRatings($id, $sort);
}

/**
* @param $id
* @param $limit
* @param $sort
* @return mixed
*/
public function getRecentRatings($id, $limit = 5, $sort = 'desc')
{
return (new Rating())->getRecentRatings($id, $limit, $sort);
}

/**
* @param $id
*
Expand Down

0 comments on commit 89a201f

Please sign in to comment.