webazin/comment

comments syetem for Laravel 5

v1.0 2018-05-02 13:44 UTC

This package is auto-updated.

Last update: 2024-12-14 18:09:17 UTC


README

Latest Stable Version License

Total Downloads

Laravel Comment

comment system for laravel 5

Installation

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
];

Getting started

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.

Usage

Setup a Model

<?php

namespace App;

use webazin\comment\Traits\Commentable as Comment;
use Illuminate\Database\Eloquent\Model;

class Post extends Model implements Comment
{
    use Comment;
}

Create a comment

$user = User::first();
$post = Post::first();

$comment = $post->comment([
    'comment' => 'comment text'
], $user);

dd($comment);

Create or update a unique comment

$user = User::first();
$post = Post::first();

$comment = $post->commentUnique([
    'comment' => 'comment text'
], $user);

dd($comment);

Update a comment

$comment = $post->updateComment(1, [
    'comment' => 'comment text'
]);

Delete a comment:

$post->deleteComment(1);

fetch the Sum comment:

$post->commentCount

// $post->commentCount() also works for this.