✈️Usage

Commentable Model

Model that the comment belongs to.

Commenter Model

Model that the user belongs to.

Implement CommentableContract and import Commentable trait in commentable model.

use LakM\Comments\Concerns\Commentable;
use LakM\Comments\Contracts\CommentableContract;

class Post extends Model implements CommentableContract
{
    use Commentable;
}

Implement CommenterContract and import Commenter trait in commenter model.

use LakM\Comments\Concerns\Commenter;
use LakM\Comments\Contracts\CommenterContract;

class User extends Model implements CommenterContract
{
    use Commenter;
}

Include styles in your layout.

<html>
    <head>
        @commentsStyles
    </head>
</html>

To avoid CSS name conflicts, we recommend adding your styles to the end of the head tag.

Include scripts in your layout

<html>
    <body>
        @commentsScripts
    </body>
</html>

To improve performance we recommend adding script at the end of the body tag.

Then simply include component in your blade file

<x-comments::index :model="$post" />

You can omit the index part but make sure to include the double colon. Otherwise Laravel will search for the component in project instead of the package.

<x-comments:: :model="$post" />

or you can use components separately,

<div x-cloak x-data class="space-y-8">
    <livewire:comments-list :model="$model" />
    <hr class="text-gray-400" />
    <livewire:comments-create-form :model="$model" />
</div>

Last updated