coliving / commentable
Laravel 的可评论多态 Eloquent 模型。这是从 artisanry/commentable 分支出来的,因为该项目已被废弃。
v5.6.0
2024-05-10 08:03 UTC
Requires
- php: ^8.0|^8.1|^8.2|^8.3
- illuminate/database: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- kalnoy/nestedset: ^6.0
Requires (Dev)
- graham-campbell/testbench: ^5.7
- mockery/mockery: ^1.5
- phpunit/phpunit: 7.*|8.*|9.*|10.*|11.*
- v5.6.0
- v5.5.0
- v5.4.0
- 5.3.0
- 5.2.1
- 5.2.0
- 5.1.0
- 5.0.1
- 5.0.0
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.0
- v3.2.1
- v3.2.0
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.2
- v3.0.1
- 3.0.0
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.x-dev
- dev-master / 1.0.x-dev
- 1.0.0
- dev-support_laravel_11_php8.3
- dev-upgrade_laravel_10
- dev-support_laravel_9
- dev-support_laravel_8
- dev-update_package_info
This package is not auto-updated.
Last update: 2024-09-27 10:01:06 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 版本 2.0 (MPL-2.0)。