sagor-roy/comments 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sagor-roy/comments

最新稳定版本:1.0.0

Composer 安装命令:

composer require sagor-roy/comments

包简介

Simple comment system for Laravel 13 with AJAX support

README 文档

README

A simple, lightweight comment system for Laravel 13 with AJAX support.

Requirements

  • PHP 8.3+
  • Laravel 13.x

Installation

1. Install via Composer

composer require sagor-roy/comments

2. Publish Assets

# Publish all assets
php artisan vendor:publish --provider="SagorRoy\Comments\CommentServiceProvider"

# Or individually:
php artisan vendor:publish --tag=comments-migrations
php artisan vendor:publish --tag=comments-config
php artisan vendor:publish --tag=comments-views
php artisan vendor:publish --tag=comments-assets

3. Run Migrations

php artisan migrate

Usage

1. Make Model Commentable

Add the Commentable trait to any model you want to make commentable:

// app/Models/Article.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use SagorRoy\Comments\Traits\Commentable;

class Article extends Model
{
    use Commentable;
}

2. Display Comments in View

In your Blade template, use the @comments directive:

{{-- resources/views/articles/show.blade.php --}}
<article>
    <h1>{{ $article->title }}</h1>
    <p>{{ $article->content }}</p>
    
    @comments($article)
</article>

3. Include CSS

Add the CSS to your layout:

<link rel="stylesheet" href="{{ asset('vendor/comments/comments.css') }}">

4. Include JavaScript

Add the JavaScript to your layout:

<script src="{{ asset('vendor/comments/comments.js') }}"></script>

Configuration

Publish the config file and customize:

php artisan vendor:publish --tag=comments-config

Then edit config/comments.php:

return [
    'max_length' => env('COMMENTS_MAX_LENGTH', 1000),
    'allow_guest_replies' => env('COMMENTS_ALLOW_GUEST_REPLIES', true),
    'per_page' => env('COMMENTS_PER_PAGE', 15),
    'guest_name_required' => env('COMMENTS_GUEST_NAME_REQUIRED', true),
    'guest_name_max_length' => env('COMMENTS_GUEST_NAME_MAX', 100),
    'user_model' => env('COMMENTS_USER_MODEL', \App\Models\User::class),
];

Environment Variables

Add to your .env file:

COMMENTS_MAX_LENGTH=1000
COMMENTS_ALLOW_GUEST_REPLIES=true
COMMENTS_PER_PAGE=15
COMMENTS_GUEST_NAME_REQUIRED=true
COMMENTS_GUEST_NAME_MAX=100
COMMENTS_USER_MODEL=App\Models\User

Features

Commentable Models

Any Eloquent model can have comments by adding the Commentable trait.

Nested Comments

Supports 1 level of nested replies. Replies to replies are not allowed.

Guest Comments

Guests can leave comments with just their name. Authenticated users have their name auto-filled.

AJAX Submission

Forms submit via AJAX for better user experience.

Customizable Views

Publish and customize the Blade views to match your design.

Customizing Views

php artisan vendor:publish --tag=comments-views

Views will be copied to resources/views/vendor/comments/.

Security

  • CSRF protection enabled
  • XSS sanitization via Laravel's default escaping
  • User can only delete their own comments
  • Configurable max comment length

License

MIT License

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固