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
.
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\HasComments;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use HasComments;
}
$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());
Please see CHANGELOG for more information what has changed recently.
$ phpunit
Please see CONTRIBUTING for details.
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.