webazin/comment is a Laravel package for comments syetem for laravel 5.
It currently has 1 GitHub stars and 19 downloads on Packagist (latest version v1.0).
Install it with composer require webazin/comment.
Discover more Laravel packages by webazin
or browse all Laravel packages to compare alternatives.
Last updated
comment system for laravel 5
First, pull in the package through Composer.
composer require webazin/Comment
or add this in your project's composer.json file .
"require": {
"webazin/Comment": "^1.0",
}
And then include the service provider within app/config/app.php.
'providers' => [
webazin\Comment\CommentServiceProvider::class
];
After the package is correctly installed, you need to generate the migration.
php artisan comment:migration
It will generate the <timestamp>_create_comments_table.php migration. You may now run it with the artisan migrate command:
php artisan migrate
After the migration, one new table will be present, comments.
<?php
namespace App;
use webazin\comment\Traits\Commentable as Comment;
use Illuminate\Database\Eloquent\Model;
class Post extends Model implements Comment
{
use Comment;
}
$user = User::first();
$post = Post::first();
$comment = $post->comment([
'comment' => 'comment text'
], $user);
dd($comment);
$user = User::first();
$post = Post::first();
$comment = $post->commentUnique([
'comment' => 'comment text'
], $user);
dd($comment);
$comment = $post->updateComment(1, [
'comment' => 'comment text'
]);
$post->deleteComment(1);
$post->commentCount
// $post->commentCount() also works for this.