Skip to content

orkhanahmadov/laravel-commentable

Repository files navigation

Laravel commentable model

Latest Stable Version Latest Unstable Version Total Downloads License

Build Status Test Coverage Maintainability Quality Score StyleCI

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.

About

Laravel commentable model

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages