{"id":20381847,"url":"https://github.com/beyondcode/laravel-comments","last_synced_at":"2025-05-14T05:10:45.735Z","repository":{"id":41755348,"uuid":"147194560","full_name":"beyondcode/laravel-comments","owner":"beyondcode","description":"Add comments to your Laravel application","archived":false,"fork":false,"pushed_at":"2025-03-02T18:47:48.000Z","size":41,"stargazers_count":595,"open_issues_count":2,"forks_count":96,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-05-11T11:13:44.577Z","etag":null,"topics":["comments","laravel"],"latest_commit_sha":null,"homepage":"https://beyondco.de","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/beyondcode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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}},"created_at":"2018-09-03T11:22:42.000Z","updated_at":"2025-05-08T12:01:09.000Z","dependencies_parsed_at":"2024-06-18T13:40:54.796Z","dependency_job_id":"e25d1070-c799-446d-87e7-c19b1614b893","html_url":"https://github.com/beyondcode/laravel-comments","commit_stats":{"total_commits":23,"total_committers":10,"mean_commits":2.3,"dds":0.782608695652174,"last_synced_commit":"9605cd85455687cca64bb92bacb91cc5969d3ae9"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-comments","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-comments/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-comments/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beyondcode%2Flaravel-comments/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beyondcode","download_url":"https://codeload.github.com/beyondcode/laravel-comments/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076850,"owners_count":22010611,"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":["comments","laravel"],"created_at":"2024-11-15T02:15:42.956Z","updated_at":"2025-05-14T05:10:45.704Z","avatar_url":"https://github.com/beyondcode.png","language":"PHP","readme":"# Add comments to your Laravel application\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-comments.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-comments)\n[![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-comments.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-comments)\n\nAdd the ability to associate comments to your Laravel Eloquent models. The comments can be approved and nested.\n\n```php\n$post = Post::find(1);\n\n$post-\u003ecomment('This is a comment');\n\n$post-\u003ecommentAsUser($user, 'This is a comment from someone else');\n```\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require beyondcode/laravel-comments\n```\n\nThe package will automatically register itself.\n\nYou can publish the migration with:\n\n```bash\nphp artisan vendor:publish --provider=\"BeyondCode\\Comments\\CommentsServiceProvider\" --tag=\"migrations\"\n```\n\nAfter the migration has been published you can create the media-table by running the migrations:\n\n```bash\nphp artisan migrate\n```\n\nYou can publish the config-file with:\n\n```bash\nphp artisan vendor:publish --provider=\"BeyondCode\\Comments\\CommentsServiceProvider\" --tag=\"config\"\n```\n\n## Usage\n\n### Registering Models\n\nTo let your models be able to receive comments, add the `HasComments` trait to the model classes.\n\n```php\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse BeyondCode\\Comments\\Traits\\HasComments;\n\nclass Post extends Model\n{\n    use HasComments;\n    ...\n}\n```\n\n### Creating Comments\n\nTo create a comment on your commentable models, you can use the `comment` method. It receives the string of the comment that you want to store.\n\n```php\n$post = Post::find(1);\n\n$comment = $post-\u003ecomment('This is a comment from a user.');\n```\n\nThe comment method returns the newly created comment class.\n\nSometimes you also might want to create comments on behalf of other users. You can do this using the `commentAsUser` method and pass in your user model that should get associated\nwith this comment:\n\n```php\n$post = Post::find(1);\n\n$comment = $post-\u003ecommentAsUser($yourUser, 'This is a comment from someone else.');\n```\n\n### Approving Comments\n\nBy default, all comments that you create are not approved - this is just a boolean flag called `is_approved` that you can use in your views/controllers to filter out comments that you might not yet want to display.\n\nTo approve a single comment, you may use the `approve` method on the Comment model like this:\n\n```php\n$post = Post::find(1);\n$comment = $post-\u003ecomments-\u003efirst();\n\n$comment-\u003eapprove();\n```\n\n### Auto Approve Comments\n\nIf you want to automatically approve a comment for a specific user (and optionally model) you can let your User model implement the following interface and method:\n\n```php\nnamespace App\\Models;\n\nuse BeyondCode\\Comments\\Contracts\\Commentator;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable implements Commentator\n{\n    /**\n     * Check if a comment for a specific model needs to be approved.\n     * @param mixed $model\n     * @return bool\n     */\n    public function needsCommentApproval($model): bool\n    {\n        return false;\n    }\n\n}\n```\n\nThe `needsCommentApproval` method received the model instance that you want to add a comment to and you can either return `true` to mark the comment as **not** approved, or return `false` to mark the comment as **approved**.\n\n### Retrieving Comments\n\nThe models that use the `HasComments` trait have access to it's comments using the `comments` relation:\n\n```php\n\n$post = Post::find(1);\n\n// Retrieve all comments\n$comments = $post-\u003ecomments;\n\n// Retrieve only approved comments\n$approved = $post-\u003ecomments()-\u003eapproved()-\u003eget();\n\n```\n\n### Nesting Comments\n\n`BeyondCode\\Comments\\Comment` itself implements the `HasComments` trait, so you can comment on a comment and therefore nest them:\n\n```php\n$comment = BeyondCode\\Comments\\Comment::first();\n$comment-\u003ecommentAsUser($user, \"Hey there!\");\n```\n\n#### Deleting Replies\n\nWhen you delete a comment, you may optionally want to delete all its nested comments (replies). To optionally enable this feature, set the `delete_replies_along_comments` config property in the `config/comments.php` file to `true`.\n\n### Events\n\nWhen a new comment is added the `BeyondCode\\Comments\\Events\\CommentAdded` event will be dispatched.\nWhen a comment is deleted the `BeyondCode\\Comments\\Events\\CommentDeleted` event will be dispatched.\n\n### Testing\n\n```bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email marcel@beyondco.de instead of using the issue tracker.\n\n## Credits\n\n-   [Marcel Pociot](https://github.com/mpociot)\n-   [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondcode%2Flaravel-comments","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeyondcode%2Flaravel-comments","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeyondcode%2Flaravel-comments/lists"}