blax-software/laravel-files
Composer 安装命令:
composer require blax-software/laravel-files
包简介
Universal Laravel file management system — upload, optimize, serve, and attach files to any model.
README 文档
README
Laravel Files
A universal, plug-and-play file management system for Laravel. Upload, optimize, serve, and attach files to any Eloquent model — with disk-agnostic storage, automatic image optimization, chunked uploads, and a built-in warehouse endpoint.
Features
- Attach files to any model — polymorphic MorphToMany relationship via the
HasFilestrait - Role-based attachments — tag files as
avatar,gallery,document, etc. using theFileLinkTypeenum or custom strings - Disk-agnostic — works with any Laravel filesystem disk (local, S3, GCS, …)
- Automatic image optimization — on-the-fly resizing and WebP conversion via spatie/image
- Chunked uploads — upload large files in pieces with real-time progress broadcasting
- Warehouse endpoint — a single route that resolves and serves any file by UUID, encrypted ID, or asset path
- UUID primary keys — every file gets a unique, non-sequential identifier
- Artisan cleanup — remove orphaned files that are no longer attached to any model
Quick Start
composer require blax-software/laravel-files
Publish the config and migrations:
php artisan vendor:publish --tag=files-config php artisan vendor:publish --tag=files-migrations php artisan migrate
Add the trait to any model:
use Blax\Files\Traits\HasFiles; class User extends Model { use HasFiles; }
Attach a file:
use Blax\Files\Enums\FileLinkType; $user = User::find(1); // Upload and attach in one call $file = $user->uploadFile($request->file('avatar'), as: FileLinkType::Avatar, replace: true); // Get the avatar back $avatar = $user->getAvatar(); echo $avatar->url; // → /warehouse/019d8ab8-… echo $avatar->size_human; // → "2.4 MB"
Documentation
| Guide | Description |
|---|---|
| Installation | Requirements, installation, configuration |
| Attaching Files | The HasFiles trait, roles, attach/detach, reordering |
| File Operations | Creating files, reading/writing contents, duplication, scopes |
| Uploading | Single uploads, chunked uploads, progress events |
| Serving Files | The Warehouse, inline responses, downloads |
| Image Optimization | On-the-fly resizing, WebP, quality control |
| Configuration | Full reference for config/files.php |
| Artisan Commands | files:cleanup and maintenance |
Optional Dependencies
| Package | Purpose |
|---|---|
spatie/image ^3.8 |
Image optimization and resizing |
blax-software/laravel-roles |
Access control on the warehouse endpoint |
blax-software/laravel-websockets |
Real-time chunk upload progress via WebSockets |
Testing
composer test # or ./vendor/bin/phpunit
License
MIT — see LICENSE for details.
Star History
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-17