christianvizarra/laravel-commentable

Forked from DraperStudio - Commentable Polymorphic Eloquent Models for for Laravel 5

dev-master / 1.0.x-dev 2016-10-19 16:54 UTC

This package is not auto-updated.

Last update: 2024-04-17 18:23:32 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Install

Via Composer

$ composer require christianvizarra/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

Usage

Setup a Model

<?php

/*
 * This file is part of Laravel :package_name.
 *
 * (c) DraperStudio <hello@draperstudio.tech>
 *
 * 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;
}

Create a comment

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

$comment = $post->comment([
    'title' => 'Some title',
    'body' => 'Some body',
], $user);

dd($comment);

Create a comment as a child of another comment (e.g. an answer)

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

$parent = $post->comments->first();

$comment = $post->comment([
    'title' => 'Some title',
    'body' => 'Some body',
], $user, $parent);

dd($comment);

Update a comment

$comment = $post->updateComment(1, [
    'title' => 'new title',
    'body' => 'new body',
]);

Delete a comment

$post->deleteComment(1);

Count comments an entity has

$post = Post::first();

dd($post->getCommentCount());

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email hello@draperstudio.tech instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

=======

commentable

forked of draperstudio/laravel-commentable