|
| 1 | +# Moox Media Library |
| 2 | + |
| 3 | +A powerful media library package for Laravel and Filament, built on top of the Spatie Media Library. |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +- PHP 8.1 or higher |
| 8 | +- Laravel 10.x or higher |
| 9 | +- Filament 3.x |
| 10 | +- Spatie Media Library |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- Beautiful media library interface |
| 15 | +- Advanced search and filtering |
| 16 | +- Collection management |
| 17 | +- Media usage tracking |
| 18 | +- Write protection for important media |
| 19 | +- Smart media replacement (automatically updates all usages) |
| 20 | +- Media picker for easy integration |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +```bash |
| 25 | +# Install the package |
| 26 | +composer require moox/media |
| 27 | + |
| 28 | +# Run the installation command |
| 29 | +php artisan media:install |
| 30 | + |
| 31 | +# Install Dependencies |
| 32 | +php artisan localization:install |
| 33 | +php artisan data:install |
| 34 | +``` |
| 35 | + |
| 36 | +The installation command will: |
| 37 | +- Publish configuration files |
| 38 | +- Run necessary migrations |
| 39 | +- Register required plugins |
| 40 | +- Configure Spatie Media Library integration |
| 41 | + |
| 42 | +### Manual Publishing |
| 43 | + |
| 44 | +If you need to manually publish any assets, you can use these commands: |
| 45 | + |
| 46 | +```bash |
| 47 | +# Publish Moox Media configuration |
| 48 | +php artisan vendor:publish --tag=media-config |
| 49 | + |
| 50 | +# Publish Spatie Media Library configuration |
| 51 | +php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-config" |
| 52 | + |
| 53 | +# Publish Moox Media migrations |
| 54 | +php artisan vendor:publish --tag=media-migrations |
| 55 | + |
| 56 | +# Publish Spatie Media Library migrations |
| 57 | +php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="medialibrary-migrations" |
| 58 | +``` |
| 59 | + |
| 60 | +## Usage |
| 61 | + |
| 62 | +### Media Library |
| 63 | + |
| 64 | +The media library provides a comprehensive interface for managing your media files: |
| 65 | + |
| 66 | +- Upload files with drag-and-drop support |
| 67 | +- Configure upload behavior through media.php config (multiple, max files, file types, etc.) |
| 68 | +- Organize files into collections |
| 69 | +- Search and filter media files |
| 70 | +- View and manage file metadata |
| 71 | +- Track media usage across your application |
| 72 | +- Replace images while maintaining all usages |
| 73 | +- Prevent accidental deletion with write protection |
| 74 | +- Handle duplicate files with smart detection |
| 75 | + |
| 76 | +### Collections |
| 77 | + |
| 78 | +Collections help you organize your media files: |
| 79 | + |
| 80 | +- Create and manage collections |
| 81 | +- Assign files to specific collections |
| 82 | +- Filter media by collection |
| 83 | +- Set collection-specific permissions |
| 84 | +- Use collections in the media picker |
| 85 | + |
| 86 | +### Media Picker Integration |
| 87 | + |
| 88 | +To use the media picker in your model, you need to: |
| 89 | + |
| 90 | +1. Add the required traits to your model: |
| 91 | +```php |
| 92 | +use Spatie\MediaLibrary\HasMedia; |
| 93 | +use Spatie\MediaLibrary\InteractsWithMedia; |
| 94 | + |
| 95 | +class YourModel extends Model implements HasMedia |
| 96 | +{ |
| 97 | + use InteractsWithMedia; |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +2. Add the mediaThroughUsables relationship: |
| 102 | +```php |
| 103 | +use Moox\Media\Models\Media; |
| 104 | + |
| 105 | +public function mediaThroughUsables() |
| 106 | +{ |
| 107 | + return $this->belongsToMany( |
| 108 | + Media::class, |
| 109 | + 'media_usables', |
| 110 | + 'media_usable_id', |
| 111 | + 'media_id' |
| 112 | + )->where('media_usables.media_usable_type', '=', static::class); |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +3. Use the CustomImageColumn in your Filament resource: |
| 117 | +```php |
| 118 | +use Moox\Media\Tables\Columns\CustomImageColumn; |
| 119 | + |
| 120 | +public static function table(Table $table): Table |
| 121 | +{ |
| 122 | + return $table |
| 123 | + ->columns([ |
| 124 | + CustomImageColumn::make('media') |
| 125 | + ->circular(), |
| 126 | + // ... other columns |
| 127 | + ]); |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +4. Use the MediaPicker component in your form: |
| 132 | +```php |
| 133 | +use Moox\Media\Forms\Components\MediaPicker; |
| 134 | + |
| 135 | +public static function form(Form $form): Form |
| 136 | +{ |
| 137 | + return $form |
| 138 | + ->schema([ |
| 139 | + MediaPicker::make('media') |
| 140 | + ->collection('images') |
| 141 | + ->multiple() |
| 142 | + ->image(), |
| 143 | + // ... other fields |
| 144 | + ]); |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +## Support |
| 149 | + |
| 150 | +For questions or issues: |
| 151 | +- Create an issue on GitHub |
| 152 | +- Contact us through our support system |
0 commit comments