christianvizarra / laravel-commentable
由DraperStudio - Commentable Polymorphic Eloquent Models 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: 2024-09-18 20:29:56 UTC
README
安装
通过Composer
$ composer require christianvizarra/laravel-commentable
然后,在app/config/app.php
中包含服务提供者。
'providers' => [ DraperStudio\Commentable\ServiceProvider::class ];
最后,你需要发布并运行迁移。
php artisan vendor:publish --provider="DraperStudio\Commentable\ServiceProvider" && php artisan migrate
使用方法
设置模型
<?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; }
创建评论
$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->getCommentCount());
变更日志
请参阅CHANGELOG了解最近更改的详细信息。
测试
$ composer test
贡献
请参阅CONTRIBUTING和CONDUCT以获取详细信息。
安全
如果您发现任何安全相关的问题,请发送电子邮件至hello@draperstudio.tech而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。
=======
commentable
由draperstudio/laravel-commentable派生而来