2017 © Pedro Peláez
 

library commentable

image

namest/commentable

  • Monday, March 2, 2015
  • by luuhoangnam
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Getting Started

Provide an elegant way to interact with comment feature between your eloquent models., (*1)

Note: The package is only support Laravel 5, (*2)

Installation

Step 1: Install package, (*3)

composer require namest/commentable

Step 2: Register service provider in your config/app.php, (*4)

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

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

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

Step 4: Migrate the migration that have been published, (*6)

php artisan migrate

Step 5: Use some traits to make awesome things, (*7)

class User extends Model
{
    use \Namest\Commentable\CommenterTrait;

    // ...
}

class Post extends Model
{
    use \Namest\Commentable\CommentableTrait;

    // ...
}

Step 6: Read API below and start happy, (*8)

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, (*9)

Events

namest.commentable.prepare

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

Payloads: - $commenter: Who do this action - $message: Comment message, (*11)

Usage:, (*12)

\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, (*13)

Payloads: - $commentable: Which receive a comment from commenter - $message: Comment message, (*14)

Usage:, (*15)

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

namest.commentable.commented

When: After the $commenter left a comment on the commentable, (*16)

Payloads: - $comment: Comment instance (you can get commenter & commentable from comment instance by $comment->commenter & $comment->commentable), (*17)

Usage:, (*18)

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

The Versions