namest/commentable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

namest/commentable

最新稳定版本:v0.2.2

Composer 安装命令:

composer require namest/commentable

包简介

README 文档

README

Provide an elegant way to interact with comment feature between your eloquent models.

Note: The package is only support Laravel 5

Installation

Step 1: Install package

composer require namest/commentable

Step 2: Register service provider in your config/app.php

return [
    ...
    'providers' => [
        ...
        'Namest\Commentable\CommentableServiceProvider',
    ],
    ...
];

Step 3: Publish package resources, include: configs, migrations. Open your terminal and type:

php artisan vendor:publish --provider="Namest\Commentable\CommentableServiceProvider"

Step 4: Migrate the migration that have been published

php artisan migrate

Step 5: Use some traits to make awesome things

class User extends Model
{
    use \Namest\Commentable\CommenterTrait;
    
    // ...
}

class Post extends Model
{
    use \Namest\Commentable\CommentableTrait;
    
    // ...
}

Step 6: Read API below and start happy

API

$user = \App\User::find(1);
$post = \App\Post::find(1);

$comment = $user->comment('Awesome')->about($post); // Return \Namest\Commentable\Comment instance
$users = \App\User::wasCommentedOn($post); // Return all user was commented on a post
$posts = \App\Post::hasCommentBy($user); // Get all posts that the user was leave comment on
$comments = \Namest\Commentable\Comment::by($user); // Return all comments that the user was leave
$comments = \Namest\Commentable\Comment::by($user, 'App\Post'); // Same as above but filter only comments on posts
$user->comments; // Return all comments that the user was leave
$user->commentables; // Return all commentable (in all types)
$post->commenters; // Return all commenters (in all types)

Censoring

Set up censoring options in config/commentable.php file

Events

namest.commentable.prepare

When: Parepare for $commenter to leave a comment on the commentable and but before event namest.commentable.commenting

Payloads:

  • $commenter: Who do this action
  • $message: Comment message

Usage:

\Event::listen('namest.commentable.prepare', function ($commenter, $message) {
    // Do something
});

namest.commentable.commenting

When: Before the $commenter leave a comment on the commentable but after the event namest.commentable.prepare

Payloads:

  • $commentable: Which receive a comment from commenter
  • $message: Comment message

Usage:

\Event::listen('namest.commentable.commenting', function ($commentable, $message) {
    // Do something
});

namest.commentable.commented

When: After the $commenter left a comment on the commentable

Payloads:

  • $comment: Comment instance (you can get commenter & commentable from comment instance by $comment->commenter & $comment->commentable)

Usage:

\Event::listen('namest.commentable.commented', function ($comment) {
    // Do something
});

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固