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
<?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;
}
$user = User::first();
$post = Post::first();
$comment = $post->comment([
'title' => 'Some title',
'body' => 'Some body',
], $user);
dd($comment);
$user = User::first();
$post = Post::first();
$parent = $post->comments->first();
$comment = $post->comment([
'title' => 'Some title',
'body' => 'Some body',
], $user, $parent);
dd($comment);
$comment = $post->updateComment(1, [
'title' => 'new title',
'body' => 'new body',
]);
$post->deleteComment(1);
$post = Post::first();
dd($post->getCommentCount());
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.