jafaripur / laravel-comment
该软件包已被废弃,不再维护。没有建议替代包。
Laravel评论系统
dev-master
2015-10-31 17:54 UTC
Requires
- php: >=5.4.0
- illuminate/support: >=5.0 <6.0
Requires (Dev)
- illuminate/database: >=5.0 <6.0
Suggests
- illuminate/database: Save comments to a database table.
This package is not auto-updated.
Last update: 2021-02-05 22:40:16 UTC
README
用于Laravel的持久性、应用程序范围内的评论系统。
安装
composer require jafaripur/laravel-comment
- 将
jafaripur\LaravelComments\ServiceProvider
添加到config/app.php
中的提供者数组。 - 运行
php artisan vendor:publish
以发布配置文件。该配置文件将允许您控制使用哪种存储引擎,以及一些特定存储的注释。 - 可选:将
'Comments' => 'jafaripur\LaravelComments\Facade'
添加到config/app.php
中的别名数组。
使用
您可以通过其外观或通过类型提示抽象类 jafaripur\LaravelComments\CommentStore
来注入它来访问评论存储。
读取函数 Closure 提供要添加到查询条件的字段列表。
<?php Comment::read(function($fields) use ($item){ $fields->namespace = $item['namespace']; $fields->threadId = $item['thread_id']; $fields->parentId = $item['parent_id']; $fields->approved = $item['approved']; $fields->userId = $item['user_id']; }); Comment::save(function($fields) use ($item){ $fields->namespace = $item['namespace']; $fields->threadId = $item['thread_id']; $fields->content = $item['content']; $fields->parentId = $item['parent_id']; $fields->approved = $item['approved']; $fields->userId = $item['user_id']; }); Comment::delete($id); Comment::approve($id); Comment::unapprove($id); ?>
数据库存储
使用迁移文件
如果您使用数据库存储,则需要运行 php artisan migrate --path=vendor/jafaripur/laravel-comment/src/migrations
以生成表。
示例
如果您需要更精细地控制查询哪些数据,可以使用 setConstraint
方法,该方法接受一个带有两个参数的闭包
$query
是查询构建器实例$insert
是一个布尔值,表示查询是否为插入。如果是插入,通常不需要对$query
做任何事情。
<?php Comment::setConstraint(function($query, $insert) { if ($insert) return; $query->where(/* ... */); }); ?>
自定义存储
此软件包在底层使用Laravel的 Manager
类,因此如果您想以其他方式存储,则很容易添加自己的自定义会话存储驱动程序。您需要做的就是扩展抽象类 CommentStore
,实现抽象方法,并调用 Comment::extend
。
<?php class MyStore extends jafaripur\LaravelComments\CommentStore { // ... } Comment::extend('mystore', function($app) { return $app->make('MyStore'); }); ?>
联系
如果您有任何问题或建议,请通过GitHub打开问题或请求拉取。