PHPackages                             wsmallnews/comment - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. wsmallnews/comment

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

wsmallnews/comment
==================

Wsmallnews system comment modules

v1.0.1(1mo ago)10[4 PRs](https://github.com/Wsmallnews/comment/pulls)1MITPHPPHP ^8.2CI passing

Since Apr 11Pushed 1w ago1 watchersCompare

[ Source](https://github.com/Wsmallnews/comment)[ Packagist](https://packagist.org/packages/wsmallnews/comment)[ Docs](https://github.com/wsmallnews/comment)[ GitHub Sponsors](https://github.com/Wsmallnews)[ RSS](/packages/wsmallnews-comment/feed)WikiDiscussions v1 Synced 1w ago

READMEChangelog (3)Dependencies (11)Versions (7)Used By (1)

A versatile commenting system built on Laravel + Filament
=========================================================

[](#a-versatile-commenting-system-built-on-laravel--filament)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ea3a862a43edeee0d861bfa29675781c99b24b0c858fc5b38c10c47f4a422e47/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77736d616c6c6e6577732f636f6d6d656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/wsmallnews/comment)[![GitHub Tests Action Status](https://camo.githubusercontent.com/998c7201efececf0926415d5e878943660ae4200e5a336cdd9034797af76e1bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f77736d616c6c6e6577732f636f6d6d656e742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/wsmallnews/comment/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/e96350ca71bcb634151f7b5aaf06e0c04badf2e66b3c710ca9ec8f9ed3894d6f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f77736d616c6c6e6577732f636f6d6d656e742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/wsmallnews/comment/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c91a9a1a5d7255346303979acfa9931cda122fa11a31b9b9dd4e38ac0bacbbd7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77736d616c6c6e6577732f636f6d6d656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/wsmallnews/comment)

A versatile commenting system built on Laravel + Filament. It supports multi-tenancy, multi-scope isolation, nested replies, likes, rich text content, out-of-the-box front-end Livewire components, and Filament admin panel.

Overview
--------

[](#overview)

- **Polymorphic Comments**：Any Eloquent model can be a comment subject (Commentable)
- **Polymorphic Commenters**：Support any model as a commenter (Commenter)
- **Nested Replies**：Support two-level replies, automatically associate with the replied-to (BeReplyer)
- **Scope Isolation**：Through scope\_type + scope\_id, multi-scope data isolation is achieved
- **Multi-Tenantancy Support**：Automatically associate with team team\_id
- **Content Types**：Support plain text, rich text (Richtext), and Markdown content types
- **Comment Status**：Support normal, pending, and hidden comment statuses
- **Like Function**：Based on [Wsmallnews/preference](https://github.com/wsmallnews/preference) extension
- **Filament Admin Panel**：Full comment management page
- **Front-end Livewire Components**：开箱即用的 Livewire comment list and comment input components
- **Highly Configurable**：Support custom models, default status, content types, etc
- **Register the CommentPlugin**：Based on [bezhansalleh/filament-plugin-essentials](https://github.com/bezhansalleh/filament-plugin-essentials) extension

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require wsmallnews/comment:^1.0
```

Installing this package will publish the configuration files and migration files of both the third-party dependency package and the current package:

```
php artisan sn-comment:install
```

You can publish only the config file individually:

```
php artisan vendor:publish --tag="sn-comment-config"
```

Publish and run only the migrations individually:

```
php artisan vendor:publish --tag="sn-comment-migrations"
php artisan migrate
```

Multi language support, you can publish the language files using

```
php artisan vendor:publish --tag="sn-comment-translations"
```

Optionally, you can publish the views using:

```
php artisan vendor:publish --tag="sn-comment-views"
```

This is the contents of the published config file:

```
use Wsmallnews\Comment\Enums\CommentStatus;
use Wsmallnews\Comment\Models;
use Wsmallnews\Support\Enums\ContentType;

return [
    /**
     * Default scopeable
     */
    'scopeable' => [
        'scope_type' => 'sn-comment',
        'scope_id' => 0,
    ],

    /**
     * Default comment contentType
     */
    'default_content_type' => ContentType::Textarea,

    /**
     * Default comment status
     */
    'default_status' => CommentStatus::Normal,

    /**
     * Custom models
     */
    'models' => [
        'comment' => Models\Comment::class,
        'comment_content' => Models\CommentContent::class,
    ],

    /**
     * File base directory (only used by filament default upload component (Forms\Components\FileUpload))
     */
    'file_directory' => 'sn/comment/',
];
```

Quick Start
-----------

[](#quick-start)

### 1. Add comment capability to your models

[](#1-add-comment-capability-to-your-models)

Give your models comment capability by adding the corresponding Traits:

```
use Illuminate\Database\Eloquent\Model;
use Wsmallnews\Comment\Models\Concerns\Commentable;
use Wsmallnews\Comment\Models\Concerns\Commenter;
use Wsmallnews\Comment\Models\Concerns\BeReplyer;

class Post extends Model
{
    // As commentable (the object being commented on)
    use Commentable;
}

class User extends Model
{
    // As commenter (the user commenting on the object)
    use Commenter;

    // As be replyer
    use BeReplyer;
}
```

### 2. Use the Livewire component

[](#2-use-the-livewire-component)

Use the Livewire component in your Blade view:

```

```

### 3. Custom theme

[](#3-custom-theme)

You should use a [filament custom theme](https://filamentphp.com/docs/5.x/styling/overview#creating-a-custom-theme)

You should add the following code to your custom theme file. If you custom theme file is `/resources/css/filament/admin/theme.css`

```
@import '../../../../vendor/wsmallnews/support/resources/css/index.css';
@import '../../../../vendor/wsmallnews/comment/resources/css/index.css';
```

Filament Integration
--------------------

[](#filament-integration)

### Register the CommentPlugin

[](#register-the-commentplugin)

Register the CommentPlugin in your Panel configuration:

```
use Wsmallnews\Comment\CommentPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            CommentPlugin::make()
                ->forResource(CommentPage::class)
                ->navigationLabel('Comment manage')
                ->navigationGroup('Website manage')
                ->navigationIcon(Heroicon::OutlinedChatBubbleLeft)
                ->activeNavigationIcon(Heroicon::ChatBubbleLeft)
                ->navigationSort(10)
                ->modelLabel('Comment')
                ->pluralModelLabel('Comments')
                ->customProperties([
                    'contentType' => ContentType::Textarea,
                    'commentStatus' => CommentStatus::Normal,
                    'emptyLabel' => 'No comments',
                    'emptyTipLabel' => 'Add your first comment',
                ]),
        ]);
}
```

#### Available Properties

[](#available-properties)

You can use the `customProperties()` method to customize the following properties:

PropertyDescriptionDefault`contentType`Content type enum`ContentType::Textarea``commentStatus`Comment status enum`CommentStatus::Normal``emptyLabel`Empty comment labelLanguage package default`emptyTipLabel`Empty comment tip labelLanguage package default### Backend Page

[](#backend-page)

After registration, you can view all comments in the Filament backend navigation:

#### Custom comment page

[](#custom-comment-page)

To customize the comment page, you can extend `Wsmallnews\Comment\Filament\Pages\Comment\Base` class in your own namespace:

```
