Skip to content

Commit 24f7e14

Browse files
committed
Version 2 Wip
1 parent a2890f4 commit 24f7e14

17 files changed

+913
-529
lines changed

README.md

Lines changed: 110 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,179 @@
11
# Laravel Review Rateable
22
<img alt="Packagist Downloads" src="https://img.shields.io/packagist/dt/codebyray/laravel-review-rateable"> <img alt="GitHub" src="https://img.shields.io/github/license/codebyray/laravel-review-rateable"> <img alt="GitHub release (latest SemVer)" src="https://img.shields.io/github/v/release/codebyray/laravel-review-rateable"> <img alt="TravisCI" src="https://api.travis-ci.com/codebyray/laravel-review-rateable.svg?branch=master">
33

4-
Review Rateable system for laravel 6, 7, 8 & 9. You can rate your models by:
5-
- Overall Rating
6-
- Customer Service Rating
7-
- Quality Rating
8-
- Friendly Rating
9-
- Price Rating
4+
NOTE: This is a complete rewrite from v1. It is not compatible with previous versions of this package.
105

11-
You can also set whether the model being rated is recommended.
6+
7+
Laravel Review Ratable is a flexible package that enables you to attach reviews (with multiple ratings) to any Eloquent model in your Laravel application. The package supports multiple departments, configurable rating boundaries, review approval, and a decoupled service contract so you can easily integrate, test, and extend the functionality.
8+
9+
## Features
10+
11+
- **Polymorphic Reviews & Ratings:** Attach written reviews along with multiple rating values to any model.
12+
- **Configurable Settings:** Define custom rating keys, labels, and value boundaries (min/max) via a config file.
13+
- **Department Support:** Organize ratings by department (e.g. default, sales, support) with their own criteria.
14+
- **Review Approval:** Set a default approval status for reviews (and override per review if needed).
15+
- **Flexible Data Retrieval:** Retrieve reviews with or without ratings, filter by approval status, and calculate averages.
16+
- **Service Contract:** Use a dedicated service that implements a contract for a decoupled, testable API.
17+
18+
## Requirements
19+
20+
- PHP 8.1 or higher
21+
- Laravel 10, 11, or 12
1222

1323
## Installation
1424

15-
First, pull in the package through Composer.
25+
### 1. Install via Composer
26+
27+
In your Laravel application's root, require the package via Composer.
1628

1729
```
18-
composer require codebyray/laravel-review-rateable
30+
composer require codebyray/laravel-review-rateable:^2.0
1931
```
2032

21-
And then include the service provider within `app/config/app.php`. Note: If you are running Laravel 5.5+ this will be auto loaded for you.
33+
### 2. Publish Package Assets
34+
After installation, publish the package config and migration files:
2235

2336
```php
24-
'providers' => [
25-
Codebyray\ReviewRateable\ReviewRateableServiceProvider::class
26-
];
37+
php artisan vendor:publish --provider="Codebyray\ReviewRateable\ReviewRateableServiceProvider" --tag=config
2738
```
28-
29-
At last you need to publish and run the migration.
39+
```php
40+
php artisan vendor:publish --provider="Codebyray\ReviewRateable\ReviewRateableServiceProvider" --tag=migrations
3041
```
31-
php artisan vendor:publish --provider="Codebyray\ReviewRateable\ReviewRateableServiceProvider" --tag="migrations"
42+
Run the migrations to create the necessary database tables:
43+
```php
44+
php artisan migrate
3245
```
3346

34-
Run the migration
35-
```
36-
php artisan migrate
47+
## Configuration
48+
49+
The package configuration file is located at config/laravel-review-ratable.php. Here you can adjust global settings such as:
50+
51+
- Rating Value Boundaries:
52+
- min_rating_value: Minimum rating value.
53+
- max_rating_value: Maximum rating value.
54+
- Review Approval:
55+
- review_approved: Default approval status for new reviews.
56+
- Departments & Rating Labels: Define multiple departments, each with its own set of rating keys and labels.
57+
58+
### Example configuration:
59+
```php
60+
<?php
61+
62+
return [
63+
'min_rating_value' => 1,
64+
'max_rating_value' => 10,
65+
'review_approved' => false, // Reviews will be unapproved by default
66+
67+
'departments' => [
68+
'default' => [
69+
'ratings' => [
70+
'overall' => 'Overall Rating',
71+
'customer_service' => 'Customer Service Rating',
72+
'quality' => 'Quality Rating',
73+
'price' => 'Price Rating',
74+
'recommendation' => 'Would Recommend?',
75+
],
76+
],
77+
'sales' => [
78+
'ratings' => [
79+
'overall' => 'Overall Rating',
80+
'communication' => 'Communication Rating',
81+
'follow_up' => 'Follow-Up Rating',
82+
'recommendation' => 'Would Recommend?',
83+
],
84+
],
85+
'support' => [
86+
'ratings' => [
87+
'overall' => 'Overall Rating',
88+
'speed' => 'Response Speed',
89+
'knowledge' => 'Knowledge Rating',
90+
'recommendation' => 'Would Recommend?',
91+
],
92+
],
93+
],
94+
];
3795
```
3896

3997
-----
4098

41-
### Setup a Model
99+
## Usage
100+
### Making a Model Reviewable
101+
To allow a model to be reviewed, add the ``ReviewRatable`` trait to your model. For example, in your ``Product`` model:
42102
```php
43103
<?php
44104

45-
namespace App;
105+
namespace App\Models;
46106

47-
use Codebyray\ReviewRateable\Contracts\ReviewRateable;
48-
use Codebyray\ReviewRateable\Traits\ReviewRateable as ReviewRateableTrait;
49107
use Illuminate\Database\Eloquent\Model;
108+
use CodeByRay\LaravelReviewRatable\Traits\ReviewRatable;
50109

51-
class Post extends Model implements ReviewRateable
110+
class Product extends Model
52111
{
53-
use ReviewRateableTrait;
112+
use ReviewRatable;
54113
}
55114
```
56-
57-
### Create a rating
58-
When creating a rating you can specify whether the rating is approved or not by adding approved to the array. This is optional and if left
59-
out the default is not approved to allow for review before posting.
115+
### Adding a Review
116+
You can add a review (with ratings) directly via the trait:
60117
```php
61-
$user = User::first();
62-
$post = Post::first();
63-
64-
$rating = $post->rating([
65-
'title' => 'This is a test title',
66-
'body' => 'And we will add some shit here',
67-
'customer_service_rating' => 5,
68-
'quality_rating' => 5,
69-
'friendly_rating' => 5,
70-
'pricing_rating' => 5,
71-
'rating' => 5,
72-
'recommend' => 'Yes',
73-
'approved' => true, // This is optional and defaults to false
74-
], $user);
75-
76-
dd($rating);
118+
$product = Product::find(1);
119+
120+
$product->addReview([
121+
'review' => 'Great product! The quality is superb and customer service was excellent.',
122+
'department' => 'sales', // Optional, defaults to 'default'
123+
'recommend' => true,
124+
'approved' => true, // Optionally override default approval (false) by providing 'approved'
125+
'ratings' => [
126+
'overall' => 5,
127+
'customer_service' => 4,
128+
'quality' => 5,
129+
'price' => 4,
130+
],
131+
], auth()->id());
77132
```
78133

79134
### Update a rating
80135
```php
81-
$rating = $post->updateRating(1, [
82-
'title' => 'new title',
83-
'body' => 'new body',
84-
'customer_service_rating' => 1,
85-
'quality_rating' => 1,
86-
'friendly_rating' => 3,
87-
'pricing_rating' => 4,
88-
'rating' => 4,
89-
'recommend' => 'No',
90-
'approved' => true, // This is optional and defaults to false
91-
]);
136+
// In Progress
92137
```
93138
### Marking review as approved
94139
```php
95-
$rating = $post->updateRating(1, ['approved' => true]);
140+
// Inm progress
96141
```
97142
### Delete a rating:
98143
```php
99-
$post->deleteRating(1);
144+
// Inm progress
100145
```
101146

102147
### Fetch approved or not approved reviews/ratings for a particular resource
103148
```php
104-
// Get approved ratings
105-
$ratings = $post->getApprovedRatings($post->id, 'desc');
106-
107-
// Get not approved ratings
108-
$ratings = $post->getNotApprovedRatings($post->id, 'desc');
109-
110-
// Get all ratings whether approved or not
111-
$ratings = $post->getAllRatings($post->id, 'desc');
112-
113-
// Get the most recent ratings (limit and sort are optional)
114-
// Limit default is 5, sort default is desc
115-
$ratings = $post->getRecentRatings($post->id, 5, 'desc');
116-
117-
// Get the most recent user ratings (limit and sort are optional)
118-
// Limit default is 5, approved default is true, sort default is desc
119-
$userRatings = $post->getRecentUserRatings($user->id, 5, true, 'desc');
120-
149+
// Inm progress
121150
```
122151
### Fetch the average rating:
123152
````php
124-
// Get Overall Average Rating
125-
$post->averageRating()
126-
127-
// Get Customer Service Average Rating
128-
$post->averageCustomerServiceRating()
129-
130-
// Get Quality Average Rating
131-
$post->averageQualityRating()
132-
133-
// Get Friendly Average Rating
134-
$post->averageFriendlyRating()
135-
136-
// Get Price Average Rating
137-
$post->averagePricingRating()
138-
153+
// Inm progress
139154
````
140155

141156
or
142157

143158
````php
144-
$post->averageRating(2) //round to 2 decimal place
145-
$post->averageRating(null, true) //get only approved average rating
159+
// Inm progress
146160
````
147161

148162
### Get all ratings:
149163
```php
150-
$post = Post::first();
151-
152-
$ratings = $post->getAllRatings($post->id);
164+
// Inm progress
153165
```
154166

155167
### Count total rating:
156168
````php
157-
$post->countRating()
169+
// Inm progress
158170
````
159171

160172
### Fetch the rating percentage.
161173
This is also how you enforce a maximum rating value.
162174
````php
163-
$post->ratingPercent()
164-
165-
$post->ratingPercent(10)); // Ten star rating system
166-
// Note: The value passed in is treated as the maximum allowed value.
167-
// This defaults to 5 so it can be called without passing a value as well.
175+
// Inm progress
168176
````
169177

170-
### Note
171-
This is a fork from Trexology's - [Original Code - laravel-reviewRateable
172-
](https://github.com/Trexology/laravel-reviewRateable).
178+
### Notes
173179

174-
Please note that this code is not used in the original and is not maintained.

composer.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codebyray/laravel-review-rateable",
3-
"description": "Review & Rating system for Laravel 7, 8 & 9",
3+
"description": "Review & Rating system for Laravel 10, 11 & 12",
44
"keywords": ["rating", "Ratable", "laravel", "Review-Rateable", "reviewable"],
55
"license": "MIT",
66
"authors": [
@@ -10,20 +10,22 @@
1010
}
1111
],
1212
"minimum-stability": "dev",
13+
"prefer-stable": true,
1314
"repositories": [
1415
{
1516
"type": "vcs",
16-
"url": "http://github.com/sundarocs/laravel-review-rateable"
17+
"url": "http://github.com/codebyray/laravel-review-rateable"
1718
}
1819
],
1920
"require": {
20-
"php" : "^7.4|^8.0",
21-
"illuminate/database": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0",
22-
"illuminate/support": "~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0"
21+
"php": ">=8.1",
22+
"illuminate/config": "^10.0 || ^11.0 || ^12.0",
23+
"illuminate/database": "^10.0 || ^11.0 || ^12.0",
24+
"illuminate/support": "^10.0 || ^11.0 || ^12.0"
2325
},
2426
"require-dev": {
25-
"phpunit/phpunit": "^6.3|^7.0|^8.0|^9.0|^9.5|^10",
26-
"orchestra/testbench": "~3.5.0|~3.6.0|^4.0|^5.0|^6.0|^7.0|^8.0"
27+
"orchestra/testbench": "^6.23 || ^7.0 || ^8.0 || ^9.0 || ^10.0",
28+
"pestphp/pest": "^1.20 || ^2.0 || ^3.0"
2729
},
2830
"autoload": {
2931
"psr-4": {
@@ -32,7 +34,12 @@
3234
},
3335
"autoload-dev": {
3436
"psr-4": {
35-
"Codebyray\\ReviewRateable\\Test\\": "tests"
37+
"Codebyray\\ReviewRateable\\Tests\\": "tests"
38+
}
39+
},
40+
"config": {
41+
"allow-plugins": {
42+
"pestphp/pest-plugin": true
3643
}
3744
},
3845
"extra": {
@@ -43,7 +50,6 @@
4350
}
4451
},
4552
"scripts": {
46-
"test": "vendor/bin/phpunit",
47-
"test:windows": "vendor\\bin\\phpunit"
53+
"test": "vendor/bin/pest"
4854
}
4955
}

config/review-ratable.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)