eliminationzx/laravel-orchid-media-library
Composer 安装命令:
composer require eliminationzx/laravel-orchid-media-library
包简介
Laravel Orchid Media Library Wrapper - Seamless integration of Spatie Media Library with Orchid Platform
README 文档
README
A comprehensive media management package for Laravel Orchid Platform that seamlessly integrates Spatie's Laravel Media Library with Orchid's admin interface. This package provides a complete media management solution with configuration-driven customization, comprehensive testing, and modern PHP 8.3+ features.
✨ Features
- Complete Media Management: Upload, organize, and manage media files through Orchid's admin interface
- Configuration-Driven: Extensive configuration system for customizing every aspect of the media library
- Modern PHP Support: Built with PHP 8.3+ features including strict typing and modern patterns
- Comprehensive Testing: Full test suite with PHPUnit and PHPStan integration
- Image Conversions: Built-in image conversion system with configurable presets
- Responsive Components: Blade components for displaying media in your applications
- Type Safety: Full type hints and PHPStan level 9 compliance
- Developer Experience: Laravel Pint for code formatting, comprehensive IDE support
📋 Requirements
- PHP 8.3 or higher
- Laravel 10.x or 11.x
- Orchid Platform 14.x
- Spatie Laravel Media Library 11.x
🚀 Installation
1. Install via Composer
composer require eliminationzx/laravel-orchid-media-library
2. Install Package Resources
Run the installation command to set up the package:
php artisan orchid-media-library:install
This command will:
- Publish stubs for screens, routes, and images
- Set up the necessary database migrations (if using Spatie Media Library)
- Configure the basic package structure
4. Run Migrations
If you haven't already installed Spatie's Media Library, run its migrations:
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="media-library-migrations" php artisan migrate
⚙️ Configuration-Free Architecture
This package uses a configuration-free architecture with sensible defaults. Instead of configuration files, it uses:
1. Constants for Defaults
All package settings are defined as class constants with sensible defaults:
// MediaService constants MediaService::SCREEN_NAME = 'Media' MediaService::SCREEN_ICON = 'film' MediaService::SCREEN_PLURAL = 'media' MediaService::ROUTE_PREFIX = 'platform' MediaService::ROUTE_MIDDLEWARE = ['web', 'platform'] MediaService::ALLOWED_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif'] // ConversionService constants ConversionService::PLATFORM_CONVERSION = [ 'width' => 100, 'height' => 100, 'crop' => 'center', 'quality' => 70, 'optimize' => true, 'queue' => false, 'enabled' => true, ]
2. Runtime Customization API
Customize settings at runtime without configuration files:
// Customize media library settings MediaService::customize([ 'screen_name' => 'Media Files', 'screen_icon' => 'image', 'allowed_mime_types' => ['image/jpeg', 'image/png', 'image/gif', 'image/webp'], 'route_middleware' => ['web', 'platform', 'auth'], ]); // Get customized values $allowedTypes = MediaService::getAllowedMimeTypes(); $routePrefix = MediaService::getRoutePrefix();
3. Spatie Media Library Configuration
Media-specific settings use Spatie's Media Library configuration (config/media-library.php):
// The package respects Spatie's configuration for: // - Disk name (config('media-library.disk_name')) // - Max file size (config('media-library.max_file_size')) // - Image quality (config('media-library.image_quality')) // - And other media-specific settings
4. Available Customization Options
| Setting | Constant | Default | Customization Method |
|---|---|---|---|
| Screen Name | SCREEN_NAME |
'Media' |
MediaService::customize(['screen_name' => '...']) |
| Screen Icon | SCREEN_ICON |
'film' |
MediaService::customize(['screen_icon' => '...']) |
| Route Prefix | ROUTE_PREFIX |
'platform' |
MediaService::customize(['route_prefix' => '...']) |
| Route Middleware | ROUTE_MIDDLEWARE |
['web', 'platform'] |
MediaService::customize(['route_middleware' => [...]]) |
| Allowed MIME Types | ALLOWED_MIME_TYPES |
['image/jpeg', 'image/png', 'image/gif'] |
MediaService::customize(['allowed_mime_types' => [...]]) |
| Platform Conversion | PLATFORM_CONVERSION |
See above | Modify ConversionService::PLATFORM_CONVERSION constant |
| OpenGraph Conversion | OPENGRAPH_CONVERSION |
128x128, center crop | Modify ConversionService::OPENGRAPH_CONVERSION constant |
| Thumbnail Conversion | THUMBNAIL_CONVERSION |
300x300, center crop | Modify ConversionService::THUMBNAIL_CONVERSION constant |
5. Resetting Customizations
Clear runtime customizations to restore defaults:
MediaService::clearCustomizations();
📖 Usage
Accessing Media in Orchid Admin
Once installed, the media library will be available in your Orchid admin panel at /platform/media. You can:
- Upload Files: Drag and drop or click to upload media files
- Organize Media: Create collections, add descriptions, and manage metadata
- Preview Media: View images, documents, and other file types
- Edit Metadata: Update file names, descriptions, and other properties
Using Media Service
The package provides a MediaService class for accessing configuration-based settings:
use Orchid\MediaLibrary\Services\MediaService; // Get screen configuration $screenName = MediaService::getName(); // 'Media' $screenIcon = MediaService::getIcon(); // 'film' // Get route names $listRoute = MediaService::getRouteList(); // 'platform.media.list' $showRoute = MediaService::getRouteShow(); // 'platform.media.show' $editRoute = MediaService::getRouteEdit(); // 'platform.media.edit'
Using Conversion Service
The ConversionService provides methods for working with image conversions:
use Orchid\MediaLibrary\Services\ConversionService; // Apply a conversion to media $convertedUrl = ConversionService::applyConversion($media, 'thumbnail'); // Check if a conversion is enabled if (ConversionService::isConversionEnabled('platform')) { // Apply platform conversion }
Blade Components
Use the included Blade components to display media in your views:
{{-- Image preview component --}} <x-orchid-laravel-media-library::components.platform.image-preview-component :media="$media" :conversion="'thumbnail'" /> {{-- Media link component --}} <x-orchid-laravel-media-library::components.platform.media-link :media="$media" :label="'View Media'" />
Table Definitions in Orchid Screens
Use the included TD (Table Definition) components in your Orchid screens:
use Orchid\MediaLibrary\Orchid\Helpers\TD\ImagePreviewTD; TD::make('preview', 'Preview') ->component(ImagePreviewTD::class) ->width('100px'),
🧪 Testing
The package includes a comprehensive test suite. To run tests:
# Run all tests composer test # Run tests with coverage report composer test-coverage # Run static analysis with PHPStan composer analyse # Format code with Laravel Pint composer format
Test Structure
- Unit Tests: Test individual components and services
- Feature Tests: Test integration with Laravel and Orchid
- Provider Tests: Test service provider registration and bootstrapping
🏗️ Development
Development Setup
- Clone the repository
- Install dependencies:
composer install - Run tests:
composer test - Check code quality:
composer analyse
Code Style
The package uses Laravel Pint for code formatting. Run composer format to automatically format code according to the project standards.
Static Analysis
PHPStan is configured at level 9 for maximum type safety. Run composer analyse to check for type errors and code quality issues.
📄 License
This package is open-source software licensed under the MIT license.
🏆 Credits
- Eliminationzx
- Spatie - For the excellent Laravel Media Library package
- Orchid Platform - For the powerful Laravel admin panel
- All Contributors
🔗 Links
Laravel Orchid Media Library - Professional media management for Laravel Orchid applications.
eliminationzx/laravel-orchid-media-library 适用场景与选型建议
eliminationzx/laravel-orchid-media-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「admin」 「cms」 「laravel」 「spatie」 「orchid」 「media-library」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eliminationzx/laravel-orchid-media-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eliminationzx/laravel-orchid-media-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eliminationzx/laravel-orchid-media-library 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Analysis module for finding problematical shop data.
Integrate with Snipcart.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-22