Add an opt-in star rating for comments#111
Open
ItsMalikJones wants to merge 3 commits into
Open
Conversation
Lets a user attach a star rating to a comment, review-style. - New nullable `rating` column via an additive migration; the Comment model casts it to an integer. - Opt-in: a `commentions.ratings` config block (disabled by default) plus CommentsEntry::make()->enableRatings() / ->maxRating(), threaded through the entry and actions to the Comments component. - The Comments editor shows an interactive star input when enabled; the rating is validated (1..max) and persisted via SaveComment. - Each comment renders its rating as filled/empty stars.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #29
Summary
Lets commenters attach a star rating to a comment, review-style. The feature is disabled by default and is fully opt-in — existing installs see no behavioral change until they enable it.
Ratings can be turned on globally via config, or per-component on
CommentsEntry,CommentsAction, andCommentsTableAction, with a configurable maximum.What's included
ratingcolumn (unsignedTinyInteger) to the comments table. TheCommentmodel addsratingto$fillableand casts it to an integer.getCacheKey()now incorporates the rating so polling correctly detects rating changes.commentions.ratingsconfig block (enabled,max), backed byCOMMENTIONS_RATINGS_ENABLED/COMMENTIONS_RATINGS_MAXenv vars and exposed throughConfig::ratingsAreEnabled()/Config::getMaxRating().HasRatingsconcern addsenableRatings(bool|Closure),disableRatings(), andmaxRating(int|Closure). Component settings override the global config and thread through to the Livewire layer.nullable|integer|min:1|max:N) on both create and edit, and persisted viaSaveComment.role="group"with per-stararia-pressed/aria-label, the display usesrole="img"with anaria-label, and star labels usetrans_choicepluralization. New translation keys added toresources/lang/en/comments.php.Usage
Enable globally in
config/commentions.php:Or per component (overrides the global config):
After upgrading, publish and run the new migration:
php artisan vendor:publish --tag="commentions-migrations" php artisan migrateTesting
tests/Livewire/CommentRatingTest.php(15 tests, 36 assertions) covering: attaching a rating, ignoring it when disabled, min/max bounds rejection, per-component enable/disable andmaxRatingoverrides (including disabling when globally enabled), star rendering against per-component max, and editing a rating round-trip.