Skip to content

Latest commit

 

History

History
executable file
·
148 lines (108 loc) · 3.67 KB

README.md

File metadata and controls

executable file
·
148 lines (108 loc) · 3.67 KB

Laravel Commentable

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Install

Via Composer

$ composer require draperstudio/laravel-commentable

And then include the service provider within app/config/app.php.

'providers' => [
    DraperStudio\Commentable\ServiceProvider::class
];

At last you need to publish and run the migration.

php artisan vendor:publish --provider="DraperStudio\Commentable\ServiceProvider" && php artisan migrate

Usage

Setup a Model

<?php

/*
 * This file is part of Laravel :package_name.
 *
 * (c) DraperStudio <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace App;

use DraperStudio\Commentable\Contracts\Commentable;
use DraperStudio\Commentable\Traits\Commentable as CommentableTrait;
use Illuminate\Database\Eloquent\Model;

class Post extends Model implements Commentable
{
    use CommentableTrait;
}

Create a comment

$user = User::first();
$post = Post::first();

$comment = $post->comment([
    'title' => 'Some title',
    'body' => 'Some body',
], $user);

dd($comment);

Create a comment as a child of another comment (e.g. an answer)

$user = User::first();
$post = Post::first();

$parent = $post->comments->first();

$comment = $post->comment([
    'title' => 'Some title',
    'body' => 'Some body',
], $user, $parent);

dd($comment);

Update a comment

$comment = $post->updateComment(1, [
    'title' => 'new title',
    'body' => 'new body',
]);

Delete a comment

$post->deleteComment(1);

Count comments an entity has

$post = Post::first();

dd($post->getCommentCount());

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.