seongbae / commentable
Laravel Commentable,修复了配置名称问题
v5.0.1
2019-12-22 00:13 UTC
Requires
- php: ^7.2
- illuminate/database: ^5.8|^6.0
- illuminate/support: ^5.8|^6.0
- kalnoy/nestedset: ^5.0
Requires (Dev)
- graham-campbell/testbench: ^5.0
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.2
README
安装
使用 Composer 在项目根目录下安装此包。
$ composer require artisanry/commentable
要开始使用,您需要发布供应商资源并迁移
php artisan vendor:publish --provider="Artisanry\Commentable\CommentableServiceProvider" && php artisan migrate
用法
设置模型
<?php namespace App; use Artisanry\Commentable\Traits\HasComments; use Illuminate\Database\Eloquent\Model; class Post extends Model { use HasComments; }
创建评论
$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->commentCount());
测试
$ phpunit
安全
如果您在此包中发现安全漏洞,请发送电子邮件至 hello@basecode.sh。所有安全漏洞都将得到及时解决。
致谢
本项目得益于所有 贡献者。
许可
Mozilla Public License Version 2.0 (MPL-2.0).