mrshanebarron/comments 问题修复 & 功能扩展

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

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

mrshanebarron/comments

最新稳定版本:v1.0.1

Composer 安装命令:

composer require mrshanebarron/comments

包简介

Comments/discussion component for Laravel - supports Livewire and Vue

README 文档

README

A threaded comments component for Laravel applications. Display and manage user comments with replies, avatars, and timestamps. Works with Livewire and Vue 3.

Installation

composer require mrshanebarron/comments

Livewire Usage

Basic Usage

<livewire:sb-comments
    :comments="$comments"
    :current-user="auth()->user()->name"
/>

With Replies

<livewire:sb-comments
    :comments="$comments"
    :current-user="auth()->user()->name"
    :current-user-avatar="auth()->user()->avatar_url"
    :allow-replies="true"
/>

Livewire Props

Prop Type Default Description
comments array [] Array of comment objects
current-user string null Current user's name
current-user-avatar string null Current user's avatar URL
allow-replies boolean true Enable reply functionality

Vue 3 Usage

Setup

import { SbComments } from './vendor/sb-comments';
app.component('SbComments', SbComments);

Basic Usage

<template>
  <SbComments
    :comments="comments"
    :current-user="currentUser.name"
    :current-user-avatar="currentUser.avatar"
    @add-comment="handleAddComment"
    @add-reply="handleAddReply"
  />
</template>

<script setup>
import { ref } from 'vue';

const currentUser = { name: 'John Doe', avatar: '/avatars/john.jpg' };
const comments = ref([
  {
    id: '1',
    author: 'Jane Smith',
    avatar: '/avatars/jane.jpg',
    content: 'Great article!',
    timestamp: new Date().toISOString(),
    replies: []
  }
]);

const handleAddComment = (comment) => {
  comments.value.push(comment);
};

const handleAddReply = ({ parentIndex, comment }) => {
  comments.value[parentIndex].replies.push(comment);
};
</script>

Vue Props

Prop Type Default Description
comments Array [] Array of comment objects
currentUser String null Current user's display name
currentUserAvatar String null Current user's avatar URL
allowReplies Boolean true Enable threaded replies

Events

Event Payload Description
add-comment comment New comment submitted
add-reply { parentIndex, comment } Reply submitted

Comment Object

{
  id: 'unique-id',
  author: 'User Name',
  avatar: '/path/to/avatar.jpg',
  content: 'Comment text...',
  timestamp: '2024-01-15T10:30:00Z',
  replies: [/* nested comments */]
}

Features

  • Threaded Replies: Nested comment threads
  • Avatars: User avatars with fallback initials
  • Timestamps: Relative time display (just now, 5m ago, etc.)
  • Reply Toggle: Click to reply to specific comments
  • Cancel Reply: Easy cancel for reply mode

Styling

Uses Tailwind CSS:

  • Rounded avatars
  • Indented reply threads
  • Border separators
  • Hover states

Requirements

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

License

MIT License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-16