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
Requires
- php: ^5.6 || ^7.0
- christianvizarra/laravel-service-provider: dev-dev
- illuminate/database: 5.1.* || 5.2.*
- kalnoy/nestedset: ^3.1|^4.0
Requires (Dev)
- graham-campbell/testbench: ^3.1
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^5.0
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2025-02-05 22:15:13 UTC
README
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