Repository navigation
fix: create comments with standard keys and make the comment model configurable - #6
Merged
Merged
Conversation
…nfigurable The migration created the commentable relation with nullableUuidMorphs(), so every app had to give its commentable models UUID keys or edit the migration. It now uses nullableMorphs() and a standard auto-incrementing id; apps with UUID or ULID keys change the published migration. The comment model is set with the new `comment_model` config option, read by HasComments. An app can extend Comment, add HasUuids and point the option to its model. This replaces the undocumented container binding of the Comment class. The test fixtures use integer keys for Post, and a UuidPost with a UuidComment model on its own table covers the UUID setup end to end, deep links included.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Documentation inconsistencies and the nullable ID annotation remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Updates comment storage to use standard integer keys by default and supports configurable UUID/ULID-compatible comment models.
Changes:
- Adds validated
comment_modelconfiguration. - Replaces UUID morphs with standard morphs.
- Removes the undocumented container binding.
- Adds fixtures, tests, and documentation for custom key types.
| File | Summary |
|---|---|
tests/Fixtures/Models/UuidPost.php |
Adds a UUID commentable fixture. |
tests/Fixtures/Models/UuidComment.php |
Adds a configurable UUID comment fixture. |
tests/Fixtures/Models/Post.php |
Switches the fixture to integer keys. |
tests/Fixtures/database/migrations/0001_01_01_000000_create_fixture_tables.php |
Adds integer and UUID fixture tables. |
tests/Feature/CommentModelTest.php |
Tests integer and UUID comment models. |
src/Support/CommentModel.php |
Resolves and validates the configured model. |
src/Models/Comment.php |
Updates the commentable ID documentation. |
src/FilamentCommentsServiceProvider.php |
Removes the container binding. |
src/Concerns/HasComments.php |
Uses the configurable comment model. |
README.md |
Documents key configuration and custom models. |
database/migrations/2026_03_10_100000_create_fm_comments_table.php |
Uses standard morph keys. |
config/filament-comments.php |
Adds the comment_model option. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * Model of comments. Must extend Happenv\FilamentComments\Models\Comment, | ||
| * e.g. to add HasUuids together with a matching migration. | ||
| */ | ||
| 'comment_model' => null, |
Contributor
Author
There was a problem hiding this comment.
Right, and it went further than stale docs: that section documented the container binding, so removing it would have broken apps that use it. Fixed in 841ccd0:
CommentModel::resolve()readscomment_modelfirst and falls back to the class the container binds toComment. ThebindIfis back.- The "Comment model" section now leads with the config option and keeps
bind()as the older way that still works. - Two new tests cover it: a container binding is used when the config isn't set, and the config wins over a binding.
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.

Summary
nullableUuidMorphs('commentable'), so the default forced UUID keys on every commentable model. It now usesnullableMorphs()next to the standardid(), with a comment on how to switch to UUID or ULID morphs.comment_modeloption inconfig/filament-comments.php, next toauthor_model.HasCommentsreads it throughSupport\CommentModel::resolve(), which throws aLogicExceptionif the class doesn't extendModels\Comment. An app can extendComment, addHasUuids, adjust the published migration and point the option to its model.bind(Comment::class, ...)override keeps working whencomment_modelisn't set. The config option takes precedence.Impact on existing installs
The migration is published into the app, so apps that already have the
commentstable are not affected. Only new installs get integer morphs by default.Tests
CommentModelTest:idandcommentable_id;comment_modelset to aUuidComment(HasUuids, own table), comments on aUuidPostget UUID keys and the deep link finds them;Commentis refused.nullableUuidMorphs()put back, it fails.Postfixture now uses integer keys. The UUID setup is covered by the new fixtures.vendor/bin/pestpasses (117 tests), and phpstan, pint, rector and composer normalize are clean.