roui/model-file-manager
Composer 安装命令:
composer require roui/model-file-manager
包简介
A Laravel package to handle file storage on model level
README 文档
README
Introduction
The ModelFileManager package is a Laravel package designed to handle file storage at the model level. It provides features for uploading, deleting, and resizing files. Additionally, it supports multiple file collections and allows you to easily store and manage files such as images, documents, and more.
Requirements
- PHP: 8.3 or higher
- Laravel: 8.x or higher
- Intervention Image: 2.x
Installation
-
Install the package via Composer:
composer require roui/model-file-manager
-
Publish the configuration file:
php artisan vendor:publish --tag=config
-
Ensure the
Intervention Imagepackage is installed:composer require intervention/image
Configuration
After publishing the configuration, you will find the config file at config/modelfilemanager.php. You can customize the following settings:
- storage_disk: The default storage disk to use.
- resized_image_path: The path for storing resized images.
- default_collection: The default collection name for file uploads.
Example of config/modelfilemanager.php:
<?php return [ 'storage_disk' => env('MODEL_FILE_STORAGE_DISK', 'public'), 'resized_image_path' => env('RESIZED_IMAGE_PATH', 'resized/{width}x{height}'), 'default_collection' => env('DEFAULT_FILE_COLLECTION', 'default'), ];
Usage
-
Upload a File: You can upload a file to a model by using the
uploadFile()method. Specify the file, collection, and disk if needed.$user->uploadFile($file, 'profile_pictures');
-
Delete a File: To delete a file from a specific collection, use the
deleteFile()method:$user->deleteFile('path/to/file.jpg', 'profile_pictures');
-
Get Files: Retrieve all files from a model’s files column:
$files = $user->getFiles();
-
Get Files from a Collection: Get files from a specific collection, with optional resizing:
$files = $user->getFilesFromCollection('profile_pictures', 300, 300);
-
Replace a File: You can replace an old file with a new one in a collection:
$user->replaceFileInCollection($newFile, 'profile_pictures');
-
Get Resized Image: Get a resized version of a file by specifying dimensions:
$resizedUrl = $user->getResizedImage('path/to/file.jpg', 300, 300);
-
Automatically Cast Files as Array: The files attribute is automatically cast as an array when accessing it:
$files = $user->files; // Returns array of files
Methods Overview
- uploadFile($file, $collection = null, $disk = null): Upload a file to a collection and disk.
- deleteFile($filePath, $collection = null, $disk = null): Delete a file from a collection and disk.
- getFiles(): Get all files from the model.
- getFilesFromCollection($collection = null, $width = null, $height = null, $disk = null): Get files from a collection with optional resizing.
- replaceFileInCollection($newFile, $collection = null, $disk = null): Replace an old file with a new one in a collection.
- getResizedImage($filePath, $width, $height, $disk = null): Get a resized version of an image.
- getFirstFileFromCollection($collection = null, $width = null, $height = null, $disk = null): Get the first file from a collection.
- getFilesAttribute($value): Automatically cast the 'files' column to an array.
License
This package is open-sourced software licensed under the MIT license.
roui/model-file-manager 适用场景与选型建议
roui/model-file-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 4, 最近一次更新时间为 2024 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「file」 「storage」 「upload」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 roui/model-file-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 roui/model-file-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 roui/model-file-manager 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Laravel Media Popup to upload/view the files
PMVC Plugin for File information
Mapper for accessing resources in KWCMS
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-21