roundly-consulting / comments-for-laravel
Attach polymorphic comments to any Laravel model
Package info
github.com/roundly-consulting/comments-for-laravel
pkg:composer/roundly-consulting/comments-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- illuminate/contracts: ^12.0|^13.0
- roundly-consulting/approvals-for-laravel: ^1.0
- roundly-consulting/enums-for-laravel: ^1.0
- roundly-consulting/likes-for-laravel: ^1.0
- roundly-consulting/media-library-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
- roundly-consulting/reports-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Comments for Laravel
Polymorphic comments for any Laravel model: any model can write them and any model can receive them. Threaded replies, moderation, likes, reports, media attachments, @mentions and thread locking come built in.
Installation
Requires PHP 8.4 and Laravel 12 or 13.
composer require roundly-consulting/comments-for-laravel php artisan vendor:publish --tag="comments-migrations" php artisan vendor:publish --tag="likes-migrations" --tag="reports-migrations" --tag="approvals-migrations" --tag="media-migrations" php artisan migrate
The second publish adds the tables of the likes, reports, approvals and media-library packages
comments builds on. If your models have UUID/ULID keys, set COMMENTS_KEY_TYPE before
migrating.
Usage
Give comments with one trait, receive them with another:
use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Comments\Traits\GivesComments; use RoundlyConsulting\Comments\Traits\HasComments; class Post extends Model { use HasComments; } class User extends Model { use GivesComments; }
Then write, reply, read and moderate through the facade:
use RoundlyConsulting\Comments\Facades\Comments; $comment = Comments::on($post)->as($user)->body('Nice write-up!')->post(); Comments::on($post)->as($author)->reply($comment)->body('Thanks!')->post(); // a threaded reply $post->threadedComments()->get(); // the public thread: approved comments + replies Comments::for($post)->pending()->approveAll(); // moderate everything held for review Comments::lock($post); // no new comments on this post
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/comments-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). Please see License File for more information.