parvez/laravel-gallery-manager
Composer 安装命令:
composer require parvez/laravel-gallery-manager
包简介
A comprehensive Laravel package for managing media files (images, videos, documents, audio) with hierarchical folder structure, supporting both local and AWS S3 storage
README 文档
README
A comprehensive Laravel package for managing media files (images, videos, documents, audio) with hierarchical folder structure. Supports both local and AWS S3 storage.
Features
- 📁 Hierarchical Folder Structure - Organize media with parent-child folder relationships
- 🎨 Multi-File Type Support - Images, Videos, Documents, Audio, and more
- 🏷️ Tagging System - Tag and categorize your media files
- ☁️ Cloud Storage - Support for local, public, and AWS S3 storage
- 🔐 User Management - Optional user-specific media organization
- 🗑️ Soft Deletes - Safely delete and restore media and folders
- 📊 Auto-calculated Metrics - Automatic folder size and media count
- 🔍 Search & Filter - Search by name, type, tags, and folders
- 🎯 RESTful API - Complete API for media and folder management
- 📦 Easy Integration - Simple installation and configuration
Requirements
- PHP >= 8.1
- Laravel >= 10.0
- intervention/image ^3.0 (optional, for image processing)
Installation
composer require parvez/laravel-gallery-manager
Publish Configuration
php artisan vendor:publish --tag=gallery-config
Publish Migrations
php artisan vendor:publish --tag=gallery-migrations php artisan migrate
Publish Vue Components (Optional)
php artisan vendor:publish --tag=gallery-components php artisan vendor:publish --tag=gallery-css
Configuration
Edit config/gallery-manager.php:
return [ 'disk' => env('GALLERY_DISK', 'public'), 'storage_path' => env('GALLERY_STORAGE_PATH', 'media'), 'max_size' => env('GALLERY_MAX_SIZE', 10240), // KB 'allowed_mimes' => [ // Images, Videos, Documents, Audio 'jpg', 'jpeg', 'png', 'gif', 'webp', 'svg', 'mp4', 'avi', 'mov', 'wmv', 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'mp3', 'wav', 'ogg', ], 'routes' => [ 'prefix' => 'api/gallery', 'middleware' => ['api', 'auth:sanctum'], ], ];
Database Schema
Tables
media - Stores media files
id,user_id,original,name,type(enum: image, video, document, audio, other)path,folder_id,url,mime_type,extensionsize,width,height,durationcreated_at,updated_at,deleted_at
folders - Hierarchical folder structure
id,name,user_id,parent_idcreated_at,updated_at,deleted_at
tags - Media tags
id,name,slugcreated_at,updated_at
media_tag - Pivot table for media-tag relationships
API Endpoints
Media Endpoints
GET /api/gallery/media # List media with filters POST /api/gallery/media # Upload media file(s) GET /api/gallery/media/{id} # Get media details PUT /api/gallery/media/{id} # Update media DELETE /api/gallery/media/{id} # Delete media GET /api/gallery/media/{id}/download # Download media POST /api/gallery/media/bulk-delete # Bulk delete media
Folder Endpoints
GET /api/gallery/folders # List folders POST /api/gallery/folders # Create folder GET /api/gallery/folders/{id} # Get folder details PUT /api/gallery/folders/{id} # Update folder DELETE /api/gallery/folders/{id} # Delete folder (recursive)
Usage Examples
Upload Media
use Parvez\GalleryManager\Services\MediaService; $mediaService = app(MediaService::class); $media = $mediaService->upload($request->file('file'), auth()->id(), [ 'name' => 'My Photo', 'folder_id' => 1, 'tags' => [1, 2, 3], ]);
Create Folder
$folder = $mediaService->createFolder('Photos', auth()->id(), $parentId = null);
Get Media with Filters
$media = $mediaService->getMedia(auth()->id(), [ 'folder_id' => 1, 'type' => 'image', 'search' => 'vacation', 'tags' => [1, 2], 'per_page' => 20, ]);
Using Facade
use Parvez\GalleryManager\Facades\Gallery; $media = Gallery::upload($file, $userId);
Models
Media Model
use Parvez\GalleryManager\Models\Media; // Relationships $media->user(); $media->folder(); $media->tags(); // Helper Methods $media->isImage(); $media->isVideo(); $media->isDocument(); $media->isAudio(); // Attributes $media->formatted_size; // e.g., "2.5 MB" $media->url; // Full URL to the file
Folder Model
use Parvez\GalleryManager\Models\Folder; // Relationships $folder->user(); $folder->parent(); $folder->children(); $folder->media(); // Computed Attributes $folder->media_count; $folder->total_size; $folder->formatted_size; // Helper Methods $folder->getBreadcrumb(); // Get full path hierarchy
Tag Model
use Parvez\GalleryManager\Models\Tag; $tag->media(); // Get all media with this tag
Frontend Integration
Upload media with JavaScript:
const formData = new FormData(); formData.append('file', fileInput.files[0]); formData.append('name', 'My File'); formData.append('folder_id', 1); formData.append('tags', JSON.stringify([1, 2])); await axios.post('/api/gallery/media', formData, { headers: { 'Content-Type': 'multipart/form-data' } });
File Type Detection
The package automatically detects file types based on MIME type:
- Images:
image/* - Videos:
video/* - Audio:
audio/* - Documents: PDF, Word, Excel, PowerPoint, etc.
- Other: Everything else
Authorization
The package includes basic authorization checks. Media and folders can be:
- User-specific:
user_idis set (only owner can access) - Public:
user_idis null (anyone can access)
You can customize authorization in the MediaController.
Testing
composer test
Security
- File size limits
- MIME type validation
- User authorization checks
- Soft deletes for safe data management
Contributing
Contributions are welcome! Please submit PRs or open issues.
License
MIT License. See LICENSE for details.
Credits
- Author: Parvez Rahman
- Email: parvezrohmanfci@gmail.com
Changelog
Version 2.0.0
- ✅ Complete rewrite with new database schema
- ✅ Multi-file type support (images, videos, documents, audio)
- ✅ Hierarchical folder structure
- ✅ Improved API endpoints
- ✅ Better resource transformers
- ✅ Simplified configuration
- ✅ Enhanced models with relationships
Version 1.x
- Basic image gallery functionality
- Date-based organization
- Local and S3 storage
Support
For issues and questions:
- Open an issue on GitHub
- Email: parvezrohmanfci@gmail.com
parvez/laravel-gallery-manager 适用场景与选型建议
parvez/laravel-gallery-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 4, 最近一次更新时间为 2026 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「media」 「storage」 「s3」 「upload」 「laravel」 「gallery」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 parvez/laravel-gallery-manager 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 parvez/laravel-gallery-manager 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 parvez/laravel-gallery-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
Simple Sharing generates social media share links within CP entry pages, allowing you to quickly & easily share entries.
Laravel Media Popup to upload/view the files
Asset Manager Laravel package for Gigcodes UI Library
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-03