1. Go to this page and download the library: Download namest/commentable library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class User extends Model
{
use \Namest\Commentable\CommenterTrait;
// ...
}
class Post extends Model
{
use \Namest\Commentable\CommentableTrait;
// ...
}
$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)
\Event::listen('namest.commentable.prepare', function ($commenter, $message) {
// Do something
});
\Event::listen('namest.commentable.commenting', function ($commentable, $message) {
// Do something
});
\Event::listen('namest.commentable.commented', function ($comment) {
// Do something
});