Download the PHP package zepson/laravel-comments without Composer
On this page you can find all versions of the php package zepson/laravel-comments. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zepson/laravel-comments
More information about zepson/laravel-comments
Files in zepson/laravel-comments
Package laravel-comments
Short Description Add comments to your Laravel application
License MIT
Homepage https://github.com/pro-cms/laravel-comments
Informations about the package laravel-comments
Add comments to your Laravel application
Add the ability to associate comments to your Laravel Eloquent models. The comments can be approved and nested. Read Article on zepson website https://zepson.co.tz/index.php/2020/12/31/laravel-comments-package/
Installation
You can install the package via composer:
The package will automatically register itself.
You can publish the migration with:
After the migration has been published you can create the media-table by running the migrations:
You can publish the config-file with:
Usage
Registering Models
To let your models be able to receive comments, add the HasComments
trait to the model classes.
Creating Comments
To 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.
The comment method returns the newly created comment class.
Sometimes 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
with this comment:
Approving Comments
By 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.
To approve a single comment, you may use the approve
method on the Comment model like this:
Auto Approve Comments
If 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:
The 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.
Retrieving Comments
The models that use the HasComments
trait have access to it's comments using the comments
relation:
Testing
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Novath Thomas
- Jofrey Abraham
- [Beyond Code Team-Original Code]()
License
The MIT License (MIT). Please see License File for more information.