{"id":14975332,"url":"https://github.com/secrethash/r8","last_synced_at":"2025-10-27T13:30:24.802Z","repository":{"id":57048167,"uuid":"267523314","full_name":"secrethash/r8","owner":"secrethash","description":"Laravel Package for Reviews and Ratings and Recommendations.","archived":false,"fork":false,"pushed_at":"2020-06-19T02:44:54.000Z","size":216,"stargazers_count":23,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T05:41:16.648Z","etag":null,"topics":["composer","composer-package","laravel","laravel-framework","rateable","ratings","recommendation","reviews"],"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/secrethash.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-28T07:31:19.000Z","updated_at":"2024-07-10T23:12:50.000Z","dependencies_parsed_at":"2022-08-23T17:50:21.768Z","dependency_job_id":null,"html_url":"https://github.com/secrethash/r8","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secrethash%2Fr8","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secrethash%2Fr8/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secrethash%2Fr8/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secrethash%2Fr8/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/secrethash","download_url":"https://codeload.github.com/secrethash/r8/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238497653,"owners_count":19482294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["composer","composer-package","laravel","laravel-framework","rateable","ratings","recommendation","reviews"],"created_at":"2024-09-24T13:51:52.992Z","updated_at":"2025-10-27T13:30:24.443Z","avatar_url":"https://github.com/secrethash.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# R8: Reviews, Ratings and Recommendations\n\n[![Latest Stable Version](https://poser.pugx.org/secrethash/r8/v)](//packagist.org/packages/secrethash/r8) [![Total Downloads](https://poser.pugx.org/secrethash/r8/downloads)](//packagist.org/packages/secrethash/r8) [![Dependents](https://poser.pugx.org/secrethash/r8/dependents)](//packagist.org/packages/secrethash/r8) [![Latest Unstable Version](https://poser.pugx.org/secrethash/r8/v/unstable)](//packagist.org/packages/secrethash/r8) [![License](https://poser.pugx.org/secrethash/r8/license)](./LICENSE)\n\nLaravel has always been missing a package like this, that supports dynamic rating with multiple Rating Types (ex. Like in Amazon or any e-commerce platform, Quality Rating, Customer Service Experience Ratings, etc.) with Integrated Reviews and Recommend Functionality.\n\nThe main Ideology behind this package is to make it easily adaptable for everyone's use case.\n\nReviews \u0026 Ratings system for Laravel 7. You can rate any of your models.\n\n-   Custom Rating Types (ex: Product Quality, Delivery Speed, Pricing, etc.) without any limitations.\n-   Display Overall and Average Ratings\n-   Method Chaining\n-   You can set whether the model being rated is recommended.\n\n# Installation\n\nFirst, pull in the package through Composer.\n\n```\ncomposer require secrethash/r8\n```\n\n**NOTE: The `dev-master` is _UNDER HEAVY DEVELOPMENT_**\n\nYou will need to publish and run the migrations.\n\n```\nphp artisan vendor:publish --provider=\"Secrethash\\R8\\R8ServiceProvider\" --tag=\"migrations\"\n```\n\nRun the migrations\n\n```\nphp artisan migrate\n```\n\n---\n\n## Setup\n\nSetup the model that will be reviewed, rated \u0026 recommended.\n\n```php\n\u003c?php\n\nnamespace App;\n\nuse Secrethash\\R8\\Contracts\\R8;\nuse Secrethash\\R8\\Traits\\R8Trait;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model implements R8\n{\n    \n    use R8Trait;\n\n}\n```\n\n# Usage\n\nThings will be kept simple. But to understand usage, you must understand the methodology behind it.\n\n#### Methodology\n\nThe Methodology used is:\n| Utility | Relation | With |\n|---------|------------|-----------|\n|Review | HasMany | Ratings |\n|Ratings | BelongsTo |RatingTypes|\n|Recommend|is a part of| Reviews |\n\n## Fetch\n\nTaking Simple Laravel Examples.\n\n`App\\Http\\Controllers\\PostController.php`\n\n```php\n\tpublic function show($id)\n\t{\n\t\t$post = Post::find($id);\n\n\t\treturn view('post.show')-\u003ewith('post', $post);\n\t}\n\n```\n\n### Reviews \u0026 Recommend\n\n`resources/views/post/show.blade.php`\n\n```php\n@foreach($post-\u003ereviews as $review)\n\n\t\u003ch2\u003e {{ $review-\u003etitle }} \u003c/h2\u003e\n\t\u003cp\u003e {{ $review-\u003ebody }} \u003c/p\u003e\n\t\u003cspan\u003e Recommended: {{ $review-\u003erecommend }} \u003c/span\u003e\n\t\u003cspan\u003e By: {{ $review-\u003eauthor-\u003ename }} \u003c/span\u003e\n\n@endforeach\n```\n\n### Ratings\n\n**NOTE:** A Review must be created first to Create and link One or Many ratings with it.\n\n`resources/views/post/show.blade.php`\n\n```php\n@foreach($post-\u003ereviews as $review)\n\n\t\u003ch2\u003e {{ $review-\u003etitle }} \u003c/h2\u003e\n\t\u003cp\u003e {{ $review-\u003ebody }} \u003c/p\u003e\n\t\u003cspan\u003e Recommended: {{ $review-\u003erecommend }} \u003c/span\u003e\n\t\u003cspan\u003e By: {{ $review-\u003eauthor-\u003ename }} \u003c/span\u003e\n\n\t@foreach ($review-\u003eratings as $rating)\n\t\t{{ $rating-\u003etype-\u003ename }}\n\t\t{{ $rating-\u003evalue }}\n\t@endforeach\n\n@endforeach\n```\n\n## Create\n\n### Reviews\n\n`App\\Http\\Controllers\\ReviewController.php`\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Post;\n\nclass ReviewController {\n\n    /**\n     * Store a newly created resource in storage.\n     *\n\t * @param $id\n     * @param  \\Illuminate\\Http\\Request  $request\n     * @return \\Illuminate\\Http\\Response\n     */\n\tpublic function store($id, Request $request)\n\t{\n\t\t$post = Post::find($id);\n\n\t\t// Create Review\n\t\t$review = $post-\u003ereviews()-\u003ecreate([\n            \t\t'title' =\u003e 'One More Bad Sample Review',\n            \t\t'body' =\u003e 'This is a another new sample review. This one has 4 Type Reviews.',\n            \t\t'recommend' =\u003e 'No',\n\t\t]);\n\n\t\t// Associate Author User ID\n        $review-\u003eauthor()-\u003eassociate(auth()-\u003euser()-\u003eid);\n\n\t}\n}\n```\n\n### Rating\n\n\u003e **Assumption:** A Rating Type has already been created with `'slug' =\u003e 'customer-service'`.\n\n`App\\Http\\Controllers\\ReviewController.php`\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Post;\nuse Secrethash\\R8\\Models\\RateType;\n\nclass ReviewController {\n\n    /**\n     * Store a newly created resource in storage.\n     *\n\t * @param $id\n     * @param  \\Illuminate\\Http\\Request  $request\n     * @return \\Illuminate\\Http\\Response\n     */\n\tpublic function store($id, Request $request)\n\t{\n\t\t$post = Post::find($id);\n\n\t\t// Getting the ID\n\t\t$type = RateType::where('slug', 'customer-service')-\u003efirst();\n\n\t\t// Create Review\n\t\t$review = $post-\u003ereviews()-\u003ecreate([\n            \t\t'title' =\u003e 'One More Bad Sample Review',\n            \t\t'body' =\u003e 'This is a another new sample review. This one has 4 Type Reviews.',\n            \t\t'recommend' =\u003e 'Yes', // Enum: accepts 'Yes' or 'No'\n\t\t]);\n\n\t\t// Associate Author User ID\n\t\t$review-\u003eauthor()-\u003eassociate(auth()-\u003euser()-\u003eid);\n\n\t\t// Creating Rating\n\t\t$rating = $review-\u003eratings()-\u003ecreate([\n\t\t\t'value' =\u003e 5\n\t\t]);\n\n\t\t// Associate Rating Type ID\n\t\t$rating-\u003etype()-\u003eassociate($type-\u003eid);\n\n\t\t// Saving Everything\n\t\t$review-\u003esave();\n\t\t$rating-\u003esave();\n\n\t}\n}\n```\n\n## RateTypes\n\nSimilarly, `Secrethash\\R8\\Models\\RateType` can be used to create Rating Types like _Product Quality_, _Customer Service_, _Delivery_, etc.\n\n| Fillable | Description   |\n| -------- | ------------- |\n| slug     | Sluggish Name |\n| name     | Full Name     |\n\n## Other Operations\n\nTo keep things simple, Operations like Counting Reviews and Ratings are done through well defined relations, the Laravel Way.\n\n### Counting\n\n#### Reviews\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Post;\n\nclass ReviewController {\n\n\tpublic function show($id)\n\t{\n\t\t$post = Post::find($id);\n\n\t\t$reviews = $post-\u003ereviews-\u003ecount();\n\n\t\t$approved = $post-\u003ereviews\n\t\t\t\t -\u003ewhere('approved', 1)\n\t\t\t\t -\u003ecount();\n\n\t\treturn view('post.show')-\u003ewith(['post' =\u003e $post, 'reviews' =\u003e $reviews, 'approved' =\u003e $approved]);\n\t}\n}\n```\n\n#### Ratings\n\nAssuming the counting will be performed directly in the `blade.php` file.\n\n`resources/views/post/show.blade.php`\n\n```php\n@foreach($post-\u003ereviews as $review)\n\t...\n\tTotal Ratings: {{ $review-\u003eratings-\u003ecount() }}\n\t...\n@endforeach\n```\n\n### Average\n\n#### Ratings\n\nLaravel manages collections in a smart way. And as we know that \"All multi-result sets returned by Eloquent are instances of the `Illuminate\\Database\\Eloquent\\Collection` object\" \u003csup\u003e[Laravel Docs][1]\u003c/sup\u003e\nAll you need to do is pass in the name of the table (here `value`) in the `average()` collection helper method.\n\n`resources/views/post/show.blade.php`\n\n```php\n@foreach($post-\u003ereviews as $review)\n\t...\n\tAverage Ratings: {{ $review-\u003eratings-\u003eaverage('value') }}\n\t...\n@endforeach\n```\n\n## Contributions\n\nContributions are welcomed and appreciated. Feel free to create a Pull Request or an Issue.\n\n### Database Structure\n\nAs this package is still under development, the database structure might change in future. The structure ER Diagram is provided as [XML File](./db.rd.xml) and also as an Image File.\n![Database Entity Relation Diagram](./database_structure.png)\n\n## License\n\nThis project is Licensed under MIT. See the [License File](./LICENSE) for more information.\n\n### Note\n\n\u003e This repository has been forked from [codebyray/laravel-review-rateable](https://github.com/codebyray/laravel-review-rateable.git)\n\nIt was forked initially as a head-start and a lot has been changed since then. The whole concept and methodology has been changed.\n\nPlease note that the original code does not matches the code from this repository as a lot has been changed.\n\n[1]: https://laravel.com/docs/7.x/eloquent-collections \"Laravel Docs for Eloquent Collections\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecrethash%2Fr8","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecrethash%2Fr8","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecrethash%2Fr8/lists"}