果汁/附件

Juice Attachments 插件。

0.0.2 2020-07-27 06:12 UTC

This package is auto-updated.

Last update: 2024-09-27 14:40:42 UTC


README

提供附件控制器并在你的应用路由中使用它。我们负责其他所有事情。

安装

  1. 运行 composer require 命令 composer require juice/attachments

  2. 注册 \Juice\Attachments\AttachmentsServiceProvider::class 服务提供者

  3. 复制配置文件并设置

    • Laravel - php artisan vendor:publish --provider="Juice\Attachments\AttachmentsServiceProvider"

    • Lumen - cp vendor/juice/attachments/config/juice-attachments.php config/

      (确保配置目录存在)

  4. 运行设置命令 php artisan attachment:setup

  5. 运行数据库迁移 php artisan migrate

  6. 设置你的应用路由

  7. 完成

控制器方法

*:假设路由命名空间为 \Juice\Attachments\Controllers

上传附件

  • 端点

    AttachmentController@upload

  • 方法参数

  • 查询字符串

  • 表单数据

  • 返回值

    成功上传的文件名的数组,例如。

    ["sjdwd.png", "pweog.pdf", "msptw.jpeg"]
  • 路由示例

    Route::post('/attachments', 'AttachmentController@upload');

下载附件

  • 端点

    AttachmentController@download

  • 方法参数

  • 查询字符串

  • 表单数据

  • 返回值

    Symfony\Component\HttpFoundation\BinaryFileResponse

  • 路由示例

    Route::get('/attachments/{id}', 'AttachmentController@download'); // https://example.com/attachments/sjdwd.png

垃圾附件

  • 端点

    AttachmentController@trash

  • 方法参数

  • 查询字符串

  • 表单数据

  • 返回值

    包含 success 键的 JSON 响应,例如

    {
        "success": true
    }
  • 路由示例

    Route::delete('/attachments/{id}', 'AttachmentController@trash'); // https://example.com/attachments/sjdwd.png