dfox288 / commentable
用于Laravel的Commentable多态Eloquent模型。由于原项目已废弃,这是从artisanry/commentable分叉而来
10.0.0
2023-02-28 11:01 UTC
Requires
- php: ^8.1
- illuminate/database: ^5.8|^6.0|^7.0|^8.0|^9.0|^10.0
- illuminate/support: ^5.8|^6.0|^7.0|^8.0|^9.0|^10.0
- kalnoy/nestedset: ^6.0
Requires (Dev)
- graham-campbell/testbench: ^5.0
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.2
This package is not auto-updated.
Last update: 2024-09-24 18:34:57 UTC
README
安装
使用Composer在项目的根目录中安装此包。
$ composer require coliving/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)。