andach/laravel-attachments-comments 问题修复 & 功能扩展

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

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

andach/laravel-attachments-comments

最新稳定版本:v1.0.1

Composer 安装命令:

composer require andach/laravel-attachments-comments

包简介

This is a Laravel package to allow you to add comments and attachments to models.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is a Laravel package for adding Attachments and Comments to any model.

Installation

You can install the package via composer:

composer require andach-limited/laravel-attachments-comments

You should then publish the config and migrations with:

php artisan attachments-comments:install

Usage

Using a Trait

To add the relations to a model, simply add the MorphToAttachmentsAndComments trait to the model. If only one is needed, then just use MorphToAttachments or MorphToComments by themselves.

class MyModel extends Model
{
    use MorphToAttachmentsAndComments;

    // ...
}

Adding Attachments and/or Comments

To actually add an attachment or a comment, you can use the addAttachmentAndComment(). This accepts a single string and an optional UploadedFile.

<form action="{{ route('my-model.store') }}" method="POST" enctype="multipart/form-data">
    @csrf

    <input type="text" name="comment" />
    <input type="file" name="attachment" />

    <button type="submit">Submit</button>
</form>

And in the relevant controller method...

public function store(Request $request)
{
    $model = MyModel::create();

    $model->addAttachmentAndComment($request->comment, $request->attachment);

    return redirect()->route('my-model.show', $model);
}

If handed an empty string or null attachment, the system will not create an attachment or comment silently.

Retrieving Attachments and Comments

The relations are all handled by the traits, so you can just call:

$model = new MyModel();

foreach ($model->attachments as $attachment)
{
    // ...
}

foreach ($model->comments as $comment)
{
    // ...
}

Displaying Comments and Attachments


License

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-18