{"id":41898636,"url":"https://github.com/codebyray/laravel-review-rateable","last_synced_at":"2026-01-25T14:38:29.552Z","repository":{"id":33188304,"uuid":"154455096","full_name":"codebyray/laravel-review-rateable","owner":"codebyray","description":"Review \u0026 Rating System For Laravel 10, 11 \u0026 12","archived":false,"fork":false,"pushed_at":"2025-12-21T09:33:00.000Z","size":109,"stargazers_count":307,"open_issues_count":3,"forks_count":53,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-12-23T02:11:41.399Z","etag":null,"topics":["laravel","laravel-rating","laravel-review-rateable","rating","review"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codebyray.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["codebyray"]}},"created_at":"2018-10-24T07:09:01.000Z","updated_at":"2025-12-21T09:14:30.000Z","dependencies_parsed_at":"2024-06-18T15:15:01.026Z","dependency_job_id":"6c15c6cb-e42f-4faa-85fd-badfbce5446d","html_url":"https://github.com/codebyray/laravel-review-rateable","commit_stats":{"total_commits":66,"total_committers":13,"mean_commits":5.076923076923077,"dds":0.303030303030303,"last_synced_commit":"9d51f4d74362c38aee8900419656615600d0f0dd"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/codebyray/laravel-review-rateable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebyray%2Flaravel-review-rateable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebyray%2Flaravel-review-rateable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebyray%2Flaravel-review-rateable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebyray%2Flaravel-review-rateable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codebyray","download_url":"https://codeload.github.com/codebyray/laravel-review-rateable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codebyray%2Flaravel-review-rateable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28754312,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T13:59:49.818Z","status":"ssl_error","status_checked_at":"2026-01-25T13:59:33.728Z","response_time":113,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-rating","laravel-review-rateable","rating","review"],"created_at":"2026-01-25T14:38:29.072Z","updated_at":"2026-01-25T14:38:29.542Z","avatar_url":"https://github.com/codebyray.png","language":"PHP","funding_links":["https://github.com/sponsors/codebyray"],"categories":[],"sub_categories":[],"readme":"# Laravel Review Rateable\n\u003cimg alt=\"Packagist Downloads\" src=\"https://img.shields.io/packagist/dt/codebyray/laravel-review-rateable\"\u003e \u003cimg alt=\"GitHub\" src=\"https://img.shields.io/github/license/codebyray/laravel-review-rateable\"\u003e \u003cimg alt=\"GitHub release (latest SemVer)\" src=\"https://img.shields.io/github/v/release/codebyray/laravel-review-rateable\"\u003e \u003cimg alt=\"TravisCI\" src=\"https://api.travis-ci.com/codebyray/laravel-review-rateable.svg?branch=master\"\u003e\n\nNOTE: This is a complete rewrite from v1. It is not compatible with previous versions of this package.\n\n\nLaravel Review Ratable is a flexible package that enables you to attach reviews (with multiple ratings) to any Eloquent model in your Laravel application. \nThe package supports multiple departments, configurable rating boundaries, review approval, and a decoupled service contract so you can easily integrate, test, and extend the functionality.\n\n## Features\n\n- **Reviews \u0026 Ratings:** Attach written reviews along with multiple rating values to any model.\n- **Configurable Settings:** Define custom rating keys, labels, and value boundaries (min/max) via a config file.\n- **Department Support:** Organize ratings by department (e.g. default, sales, support) with their own criteria.\n- **Review Approval:** Set a default approval status for reviews (and override per review if needed).\n- **Flexible Data Retrieval:** Retrieve reviews with or without ratings, filter by approval status, and calculate averages.\n- **Service Contract:** Use a dedicated service that implements a contract for a decoupled, testable API.\n\n## Requirements\n\n- PHP 8.1 or higher\n- Laravel 10, 11, or 12\n\n## Installation\n\n### 1. Install via Composer\n\nIn your Laravel application's root, require the package via Composer.\n\n```\ncomposer require codebyray/laravel-review-rateable:^2.0\n```\n\n### 2. Publish Package Assets\nAfter installation, publish the package config and migration files:\n\n```php\nphp artisan vendor:publish --provider=\"Codebyray\\ReviewRateable\\ReviewRateableServiceProvider\" --tag=config\n```\n```php\nphp artisan vendor:publish --provider=\"Codebyray\\ReviewRateable\\ReviewRateableServiceProvider\" --tag=migrations\n```\nRun the migrations to create the necessary database tables:\n```php\nphp artisan migrate\n```\n\n## Configuration\n\nThe package configuration file is located at config/review-ratable.php. Here you can adjust global settings such as:\n\n- Rating Value Boundaries:\n    - min_rating_value: Minimum rating value.\n    - max_rating_value: Maximum rating value.\n- Review Approval:\n    - review_approved: Default approval status for new reviews.\n- Departments \u0026 Rating Labels: Define multiple departments, each with its own set of rating keys and labels.\n\n### Example configuration:\n```php\n\u003c?php\n\nreturn [\n    'min_rating_value' =\u003e 1,\n    'max_rating_value' =\u003e 10,\n    'review_approved'  =\u003e false, // Reviews will be unapproved by default\n\n    'departments' =\u003e [\n        'default' =\u003e [\n            'ratings' =\u003e [\n                'overall'          =\u003e 'Overall Rating',\n                'customer_service' =\u003e 'Customer Service Rating',\n                'quality'          =\u003e 'Quality Rating',\n                'price'            =\u003e 'Price Rating',\n                'recommendation'   =\u003e 'Would Recommend?',\n            ],\n        ],\n        'sales' =\u003e [\n            'ratings' =\u003e [\n                'overall'        =\u003e 'Overall Rating',\n                'communication'  =\u003e 'Communication Rating',\n                'follow_up'      =\u003e 'Follow-Up Rating',\n                'recommendation' =\u003e 'Would Recommend?',\n            ],\n        ],\n        'support' =\u003e [\n            'ratings' =\u003e [\n                'overall'        =\u003e 'Overall Rating',\n                'speed'          =\u003e 'Response Speed',\n                'knowledge'      =\u003e 'Knowledge Rating',\n                'recommendation' =\u003e 'Would Recommend?',\n            ],\n        ],\n    ],\n];\n```\n\n-----\n\n## Usage\n### Making a Model Reviewable\nTo allow a model to be reviewed, add the ``ReviewRateable`` trait to your model. For example, in your ``Product`` model:\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Codebyray\\ReviewRateable\\Traits\\ReviewRateable;\n\nclass Product extends Model\n{\n    use ReviewRateable;\n}\n```\n### Adding a review/rating(s)\nYou can add a review (with ratings) directly via the trait:\n```php\n$product = Product::find($productId);\n\n$product-\u003eaddReview([\n    'review'     =\u003e 'Great product! The quality is superb and customer service was excellent.',\n    'department' =\u003e 'sales',   // Optional, defaults to 'default'\n    'recommend'  =\u003e true,      // Whether the user would recommend the product being reviewed\n    'approved'   =\u003e true,      // Optionally override default (false) approval by providing 'approved'\n    'ratings'    =\u003e [\n        'overall'        =\u003e 5,\n        'communication'  =\u003e 5,\n        'follow_up'      =\u003e 5,\n        'price'          =\u003e 5,\n    ],\n], auth()-\u003eid());\n```\n\n### Update a review/rating(s)\n```php\n// Retrieve the product you want to update the review for.\n$product = Product::findOrFail($productId);\n\n// Prepare the updated data.\n$data = [\n    'review'     =\u003e 'Updated review text',    // New review text.\n    'department' =\u003e 'sales',       // Optionally, change the department.\n    'recommend'  =\u003e false,         // Update recommendation flag.\n    'approved'   =\u003e true,          // Update approval status if needed.\n    'ratings'    =\u003e [\n        'overall'        =\u003e 4,\n        'communication'  =\u003e 3,\n        'follow_up'      =\u003e 4,\n        'price'          =\u003e 2,\n    ],\n];\n\n// Call the updateReview method on the product.\n$product-\u003eupdateReview($reviewId, $data);\n```\n### Marking review as approved\n```php\n// Retrieve the product you want to mark as approved\n$product = Product::findOrFail($productId);\n\n// Approve th review\n$product-\u003eapproveReview($reviewId);\n```\n### Delete a review/rating:\n```php\n// Retrieve the product with the review you want to delete\n$product = Product::findOrFail(1);\n\n// Delete the review\n$product-\u003edeleteReview($reviewId);\n```\n\n### Fetch approved or not approved reviews/ratings for a particular resource\n```php\n// Approved reviews with ratings\n$product = Product::findOrFail($productId);\n\n// Get approved reviews (with related ratings)\n// Default: approved: true, withRatings: true\n$product-\u003egetReviews();\n\n// Get not approved reviews (with related ratings)\n$product-\u003egetReviews(false);\n$product-\u003egetReviews(approved: false);\n\n// Get approved reviews (without related ratings)\n$product-\u003egetReviews(true, false);\n$product-\u003egetReviews(withRatings: false);\n```\n\n### Fetch approved or not approved reviews/ratings by department\n```php\n// Approved reviews department with ratings\n$product = Product::findOrFail($productId);\n\n// Get approved reviews by department (with related ratings)\n// Default: approved: true, withRatings: true\n$product-\u003egetReviewsByDepartment(\"sales\");\n\n// Get not approved reviews department (with related ratings)\n$product-\u003egetReviewsByDepartment(\"sales\", false);\n$product-\u003egetReviewsByDepartment(department: \"sales\", approved: false);\n\n// Get approved reviews department (without related ratings)\n$product-\u003egetReviewsByDepartment(\"sales\", true, false);\n$product-\u003egetReviewsByDepartment(department: \"sales\", withRatings: false);\n```\n\n### Get reviews/ratings based on a star rating.\n```php\n// Fetch the product\n$product = Product::findOrFail($productId);\n\n// Get approved reviews by star rating. The below call will return all 5-star \n// reviews/ratings for the \"support\" department.\n// Defaults: starValue: null, department: \"default\", approved: true, withRatings: true\n$product-\u003egetReviewsByRating(5, department: \"support\");\n\n// If you only want the reviews and not the ratings, add withRatings: false:\n$product-\u003egetReviewsByRating(5, department: \"support\", withRatings: false);\n```\n\n### Get the total number of reviews.\n```php\n// Approved reviews department with ratings\n$product = Product::findOrFail($productId);\n\n// Get the total number of reviews for the reviewable resource.\n// Default: approved = true\n$product-\u003etotalReviews();\n\n// Get the total number of reviews for the reviewable resource by department.\n// Defaults: department = \"default\", approved = true\n$product-\u003etotalDepartmentReviews(department: \"sales\");\n```\n\n### Fetch the average rating:\n```php\n// Retrieve a Product instance (assuming Product uses the ReviewRatable trait)\n$product = Product::findOrFail($productId);\n\n// Get the average rating for a specific key ('overall') using approved reviews (default).\n$overallAverage = $product-\u003eaverageRating('overall');\necho \"Overall Average (approved): {$overallAverage}\\n\";\n\n// Get the average rating for a specific key using non-approved reviews.\n$nonApprovedOverall = $product-\u003eaverageRating('overall', false);\necho \"Overall Average (pending): {$nonApprovedOverall}\\n\";\n\n// Get all average ratings for all rating keys from approved reviews.\n$allAverages = $product-\u003eaverageRatings();\n\n// Returns something like\n[\n    \"overall\"       =\u003e 3.5,\n    \"communication\" =\u003e 2.75,\n    \"follow_up\"     =\u003e 3.5,\n    \"price\"         =\u003e 4.25\n]\n\n// Get the overall average rating across all ratings (approved reviews by default).\n$overallRating = $product-\u003eoverallAverageRating();\n\n// Returns float\n3.5\n```\n\n### Count the total number of reviews:\n````php\n// Retrieve a Product instance (assuming Product uses the ReviewRatable trait)\n$product = Product::find($productId);\n\n// Returns the total number of reviews.\n$totalReviews = $product-\u003etotalReviews();\n\n// Get the total for a specific department\n// Defaults: department: \"default\", approved = true\n$totalDepartmentReviews = $product-\u003etotalDepartmentReviews();\n````\n\n### Return an array of rating value ⇒ count, for the full model or for a given department.\n````php\n// Retrieve a Product instance (assuming Product uses the ReviewRatable trait)\n$product = Product::find($productId);\n\n// Returns the total number of ratings. \n// Defaults: department: \"default\", approved = true\n$totalReviews = $product-\u003eratingCounts();\n\n// Returns, where the array key is the star rating and the value is the total count\narray:5▼\n  1 =\u003e 0\n  2 =\u003e 1\n  3 =\u003e 8\n  4 =\u003e 0\n  5 =\u003e 3\n]\n````\n\n### Returns a muti-denominational array with ratings stats for a given department.\n````php\n// Retrieve a Product instance (assuming the Product uses the ReviewRatable trait)\n$product = Product::find($productId);\n\n// Get the stats for a given department or the default.\n// Defaults: department: \"default\", approved = true\n$totalReviews = $product-\u003eratingStats();\n\n// Returns, where the \"counts\" array holds the count for each star rating.\n// And the \"percentages\" holds to percentage for each star rating.\n// Finally, the total number of star ratings is returned.\narray:3▼\n  \"counts\" =\u003e array:5 [▶\n    1 =\u003e 0\n    2 =\u003e 1\n    3 =\u003e 8\n    4 =\u003e 0\n    5 =\u003e 3\n  ]\n  \"percentages\" =\u003e array:5 [▶\n    1 =\u003e 0.0\n    2 =\u003e 8.0\n    3 =\u003e 67.0\n    4 =\u003e 0.0\n    5 =\u003e 25.0\n  ]\n  \"total\" =\u003e 12\n]\n````\n\n## Example Usage in a Controller\nEvery method available using the ReviewRateable Trait can also be called via the service\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Models\\Product;\nuse CodeByRay\\LaravelReviewRatable\\Contracts\\ReviewRatableContract;\nuse Illuminate\\Http\\JsonResponse;\nuse Illuminate\\Http\\Request;\n\nclass ProductReviewController extends Controller\n{\n    protected ReviewRatableContract $reviewService;\n\n    public function __construct(ReviewRatableContract $reviewService)\n    {\n        $this-\u003ereviewService = $reviewService;\n    }\n\n    public function store(Request $request): JsonResponse\n    {\n        $product = Product::find($request-\u003einput('product_id'));\n        $this-\u003ereviewService-\u003esetModel($product);\n\n        $data = [\n            'review'     =\u003e $request-\u003einput('review'),\n            'department' =\u003e $request-\u003einput('department'),\n            'recommend'  =\u003e $request-\u003eboolean('recommend'),\n            // 'approved' is optional and will default to config value.\n            'ratings'    =\u003e [\n                \"overall\"       =\u003e $request-\u003einput('overall'),\n                \"communication\" =\u003e $request-\u003einput('communication'),\n                \"follow_up\"     =\u003e $request-\u003einput('follow_up'),\n                \"price\"         =\u003e $request-\u003einput('price')\n            ]),\n        ];\n\n        $review = $this-\u003ereviewService-\u003eaddReview($data, auth()-\u003eid());\n\n        return response()-\u003ejson(['message' =\u003e 'Review added!', 'review' =\u003e $review]);\n    }\n\n    public function show(Product $product): JsonResponse\n    {\n        $this-\u003ereviewService-\u003esetModel($product);\n\n        $reviews = $this-\u003ereviewService-\u003egetReviews(); // Get approved reviews with ratings\n        $total   = $this-\u003ereviewService-\u003etotalReviews();\n\n        return response()-\u003ejson(compact('reviews', 'total'));\n    }\n}\n```\n## Testing\n```bash\ncomposer test\n```\n### Notes\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebyray%2Flaravel-review-rateable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodebyray%2Flaravel-review-rateable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodebyray%2Flaravel-review-rateable/lists"}