nirajan/comment

A Laravel package for handling comments

Maintainers

Package info

github.com/Nirajan14/comment

Language:Blade

pkg:composer/nirajan/comment

Transparency log

Statistics

Installs: 15

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.2 2026-05-28 11:06 UTC

This package is auto-updated.

Last update: 2026-06-28 11:21:53 UTC


README

License: MIT Laravel Version

A lightweight Laravel package for adding comments to any Eloquent model using polymorphic relationships.

Features

  • Polymorphic comment support for any Eloquent model
  • Blade components for comment forms and comment lists
  • Admin dashboard for moderation, approval, and deletion
  • Optional ReCAPTCHA validation support
  • Configurable middleware, URL prefix, layout, and approval workflow
  • Easy installation and package reuse

Requirements

  • PHP 8.1+
  • Laravel 10.x, 11.x, or 12.x

Installation

  1. Install the package via Composer:
composer require nirajan/comment
  1. Publish package resources:
php artisan vendor:publish --provider="Nirajan\Comment\CommentServiceProvider"
  1. Run the migrations:
php artisan migrate

Configuration

The package publishes a configuration file at config/comment.php.

Example configuration:

return [
    'admin_middleware'    => ['web', 'admin'],
    'recaptcha_site_key'  => env('RECAPTCHA_SITE_KEY'),
    'recaptcha_secret_key'=> env('RECAPTCHA_SECRET_KEY'),
    'admin_url_prefix'    => 'AdminActivity',
    'admin_layout'        => 'backend.layouts.master',
    'need_approval'       => false,
    'post_route' => [
        'name'     => 'posts.detail',
        'param'    => 'id',
        'callback' => null,
    ],
    'theme' => [
        'icon_button_color' => '#fd0000',
        'icon_button_color_secondary' => '#fd0000',
    ],
];

Important configuration options

  • admin_middleware - Middleware applied to the admin comment routes
  • admin_url_prefix - URL prefix used for the dashboard route
  • admin_layout - Blade layout used by admin views
  • need_approval - Set to true to require manual approval before comments are public
  • post_route - Redirect options for a comment reply route or detail route

Usage

Enable comments on a model

Add the HasComments trait to any model:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Nirajan\Comment\Traits\HasComments;

class Post extends Model
{
    use HasComments;
}

Display the comment form and list

Use the provided Blade components in your view:

<x-comment::comment-form :model="$post" />
<x-comment::comment-list :model="$post" />

Component props

  • comment-form expects a model instance that uses HasComments
  • comment-list expects a model instance and displays related comments

Admin Dashboard

Visit the admin dashboard at:

/ AdminActivity/comments

The dashboard supports:

  • viewing all comments
  • approving or rejecting comments
  • deleting comments
  • filtering by approval status

Update admin_url_prefix and admin_layout in config/comment.php to match your application.

ReCAPTCHA Support

If you want to enable ReCAPTCHA validation, add your keys to .env:

RECAPTCHA_SITE_KEY=your-site-key
RECAPTCHA_SECRET_KEY=your-secret-key

Then update config/comment.php accordingly.

Customization

You can customize package behavior through config/comment.php and by overriding published views in your application if needed.

License

This package is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions, issues, and pull requests are welcome. Please open an issue first if you want to propose a larger change.