orkhanahmadov / laravel-commentable
Laravel commentable model
Fund package maintenance!
orkhanahmadov
Requires
- php: ^7.2|^8.0
- illuminate/database: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-11-07 17:47:51 UTC
README
This package provides adding comments to any of your existing Eloquent models.
Requirements
- PHP 7.2 or higher
- Laravel 6 or higher
Installation
You can install the package via composer:
composer require orkhanahmadov/laravel-commentable
Publish migration and config files:
php artisan vendor:publish --provider="Orkhanahmadov\LaravelCommentable\LaravelCommentableServiceProvider"
Config
Config file contains following settings:
table_name
- here you are set table name for migration. Default is "comments".
Usage
Use Orkhanahmadov\LaravelCommentable\Commentable
trait in any of your existing Eloquent model to make it commentable.
use Illuminate\Database\Eloquent\Model; use Orkhanahmadov\LaravelCommentable\Commentable; class Post extends Model { use Commentable; }
To add a comment to your model call comment()
method from model instance.
$post = Post::find(1); $post->comment('Great post, thanks for sharing!');
To add a comment as a user call commentAs()
method from model instance.
$post = Post::find(1); $user = User::find(5); $post->commentAs($user, 'Great post, thanks for sharing!');
Each comment also saves IP address, User-Agent from request.
Testing
composer test
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 ahmadov90@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.