Skip to content

chimenk/Laravel-Commentable

 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%