Require this package, with Composer, in the root directory of your project.
$ composer require faustbrian/laravel-commentable
And then include the service provider within app/config/app.php
.
'providers' => [
BrianFaust\Commentable\CommentableServiceProvider::class
];
To get started, you'll need to publish the vendor assets and migrate:
php artisan vendor:publish --provider="BrianFaust\Commentable\CommentableServiceProvider" && php artisan migrate
<?php
namespace App;
use BrianFaust\Commentable\HasCommentsTrait;
use BrianFaust\Commentable\Interfaces\HasComments;
use Illuminate\Database\Eloquent\Model;
class Post extends Model implements HasComments
{
use HasCommentsTrait;
}
$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->commentCount());
If you discover a security vulnerability within this package, please send an e-mail to Brian Faust at [email protected]. All security vulnerabilities will be promptly addressed.
The The MIT License (MIT). Please check the LICENSE file for more details.