blytd/media-manager

此软件包最新版本(1.0.3)没有可用的许可证信息。

1.0.3 2022-10-17 21:09 UTC

This package is auto-updated.

Last update: 2024-09-18 02:33:59 UTC


README

此软件包可以将某些类型的媒体与Eloquent模型关联。它提供了一些简单的API来操作。

安装

要安装此库,请执行以下步骤

  • 将以下行添加到 composer.json 文件的 require 部分
"blytd/media-manager": "^1.0.0"
  • 并且也在 composer.json 文件中添加以下部分
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/alisarmadi/media-manager"
        }
    ],
  • 在您的 composer.json 文件中,最终应像这样
    ...
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/alisarmadi/media-manager"
        }
    ],
    "require": {
        ...
        "blytd/media-manager": "^1.0.0"
    },
    ...
  • 然后,将以下行添加到项目配置目录中的 app.php 文件
    \Blytd\MediaManager\Provider\MediaManagerProvider::class

用法

要使用此库,您必须将以下路由添加到项目的路由中

Route::name('media.')->prefix('media')->group(function (){
   Route::post('/upload',[\Blytd\MediaManager\Http\Controller\MediaController::class, 'upload'])->name('upload');
        Route::delete('/delete/{media_id?}',[\Blytd\MediaManager\Http\Controller\MediaController::class, 'delete'])->name('delete');
});

注意:请确保将这些路由包裹在适当的中间件中,以控制对其的访问。例如

Route::middleware('auth')->group(function (){
    Route::name('media.')->prefix('media')->group(function (){
   Route::post('/upload',[\Blytd\MediaManager\Http\Controller\MediaController::class, 'upload'])->name('upload');
        Route::delete('/delete/{media_id?}',[\Blytd\MediaManager\Http\Controller\MediaController::class, 'delete'])->name('delete');
    });
});

要使用此库,您有两个端点用于上传和删除,您可以通过以下路由访问它们

    POST {{base_path}}{/api}/media/upload
    PAYLOAD (form-data)
        media: (Selected file)
        model: (Can be one of your model name, it's an optional parameter)
        model_id: (Id of the selected model, it's an optional parameter)
        type: (Type of the file, can be one of (IMAGE,VIDEO,DOC,OTHER) it's an optional parameter)
        extra_data: (Extra data you want to store beside the file, It must be an array. It's an optional parameter)

    DELETE {{base_path}}{/api}/media/delete/{media_id}
    PAYLOAD
        {
            "path": "original/Team/630ee0ffb111e74b631f62b2_399a44ea-4642-4cda-94f4-3046904d311e.jpeg"
        }
    You must set one of the 'media_id' or 'path' param in this endpoint to delete the desired media.    

可选用法

您可以使用以下行发布 MediaController 并根据需要自定义它。

    php artisan vendor:publish --tag=blytd-media-controller