承接 karabinse/laravel-commentable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

karabinse/laravel-commentable

最新稳定版本:1.0.2

Composer 安装命令:

composer require karabinse/laravel-commentable

包简介

Easily add a commentable trait to a Eloquent model

README 文档

README

Latest Version on Packagist

Easily add a commentable trait to an Eloquent model

use Karabin\Commentable\Concerns\Commentable;

class Product extends Model
{
    use Commentable;

    protected $guarded = ['location'];

Installation

You can install the package via composer:

composer require karabinse/laravel-commentable

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-commentable-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="laravel-commentable-config"

This is the contents of the published config file:

return [
    'models' => [
        'comment' => \Karabin\Commentable\Models\Comment::class,
    ],

    // Add models that have comments here
    'model_map' => [
    ],

    'data' => [
        'comment' => \Karabin\Commentable\Data\CommentData::class,
    ],
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="laravel-commentable-views"

Usage

Add the trait to the model you want to add comments to.

class Customer extends Model
{
    use Commentable, HasFactory;

Configure the model map. You can also provide a data transformer for the comment itself.

use App\Data\CommentData;
use App\Models\Customer;
use App\Models\Product;

return [
    'models' => [
        'comment' => \Karabin\Commentable\Models\Comment::class,
    ],

    // Add models that have comments here
    'model_map' => [
        'customers' => Customer::class,
        'products' => Product::class,
    ],

    'data' => [
        'comment' => CommentData::class,
    ],
];

Saving a new comment:

use Karabin\Commentable\Models\Comment;

$commentModel = new Comment;
$comment = $commentModel->storeComment(
    commenter: $request->user(),
    modelName: $modelName,
    modelId: $modelId,
    comment: $request->comment,
    parentId: $request->parent_id ?? null
);

return CommentData::from($comment)->wrap('data');

Getting comments:

$commentModel = new Comment;
$comments = $commentModel->getCommentsForModel($modelName, $modelId);

return response()->json(['data' => $comments]);

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固