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

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

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

bellal22/comments

最新稳定版本:v1.0.1

Composer 安装命令:

composer require bellal22/comments

包简介

lightweight laravel package to add Comments and reply Features to your application

README 文档

README

Introduction

The Comments Package is a powerful and flexible solution for adding comment functionality to any Laravel project. Designed with scalability and ease of use in mind, it integrates seamlessly with Laravel's ecosystem.

This package allows users to add comments to any model in your application with minimal setup. It is ideal for building forums, blogs, ticketing systems, or any other application requiring a robust commenting system.

Package Banner Package Banner

Features

  • Eloquent Integration: Easily attach comments to any model.
  • Soft Deletes: Handle comment deletion without losing data.
  • Highly Configurable: Customize behaviors via configuration files.
  • PSR-4 Autoloading: Easy integration into Laravel projects.

Requirements

  • PHP 8.0+
  • Laravel 8.x or later

Installation

Install the package via Composer:

composer require bellal22/comments

Configuration

Publish Configuration File

Run the following command to publish the package's configuration file:

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

This will create a config/comments.php file where you can customize the package's behavior.

set Configuration

write your commentables Model classes in config file

'commentables' => [
        // Define models that can have comments here
        // Example: 'order' => Order::class,
    ],

Clear Configuration Cache

Run the following command to publish the package's configuration file:

php artisan config:clear
php artisan cache:clear

Migrations

Publish and run the package's migrations to set up the required database tables:

php artisan vendor:publish --tag=comments-migrations
php artisan migrate

Usage

Setting Up Models

Add the Commentable trait to any model that you want to associate with comments:

namespace App\Models;

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

class Post extends Model
{
    use Commentable;
}

Adding Comments

You can add a comment to a model instance as follows:

use App\Models\Post;
use Bellal22\Comments\Models\Comment;

$post = Post::find(1);
$comment = $post->addComment([
    'user_id' => auth()->id(),
    'content' => 'This is a great post!',
]);

Retrieving Comments

Retrieve all comments associated with a model:

$comments = $post->comments;

Delete Comment

Delete specific Comment:

$comments = $post->removeComment($comment);

Other Methods

count all comments related to model:

$comments = $post->commentCount();

get latest n comments (integer parameter) 5 is default:

$comments = $post->latestComments();

retrieve comments without replies:

$comments = $post->allComments();

Blade Components

The package provides ready-to-use Blade components for managing and displaying comments.

Comment Form

Include the comment form component in your Blade views:

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

Comments List

Render a list of comments:

<x-comments-comment-component :comment="$comment" />

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or fix.
  3. Submit a pull request with a detailed explanation of your changes.

License

This package is open-sourced software licensed under the MIT license.

Author

Developed and maintained by Bellal Hassen. Connect with me on GitHub.

Acknowledgments

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-07