PHPackages                             minemindmedia/laravel-mmmedia - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. minemindmedia/laravel-mmmedia

ActiveLibrary[File &amp; Storage](/categories/file-storage)

minemindmedia/laravel-mmmedia
=============================

A Laravel package providing a global media library and Filament MediaPicker field

v1.1.3(7mo ago)1131MITPHPPHP ^8.1

Since Sep 29Pushed 7mo agoCompare

[ Source](https://github.com/minemindmedia/laravel-mmmedia)[ Packagist](https://packagist.org/packages/minemindmedia/laravel-mmmedia)[ Docs](https://github.com/minemindmedia/laravel-mmmedia)[ RSS](/packages/minemindmedia-laravel-mmmedia/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

Laravel MMMedia
===============

[](#laravel-mmmedia)

A comprehensive Laravel package that provides a global media library and Filament MediaPicker field for managing media assets in your Laravel applications.

Features
--------

[](#features)

- 🖼️ **Global Media Library** - Centralized media management with Filament admin interface
- 📁 **MediaPicker Field** - Easy-to-use Filament form component for media selection
- 🔗 **Usage Tracking** - Track where media items are used across your application
- 📤 **File Upload** - Direct upload support with drag &amp; drop
- 🎨 **Multiple File Types** - Support for images, videos, and documents
- 🔄 **Reordering** - Reorder media items in galleries
- 🏷️ **Metadata** - Alt text, titles, captions, and custom metadata
- 💾 **Flexible Storage** - Works with any Laravel filesystem (local, S3, etc.)
- 🎯 **Model Integration** - Easy integration with any Eloquent model
- 🚀 **Filament v4 Compatible** - Native support for Filament v4
- 📚 **Spatie MediaLibrary Integration** - Works with or without Spatie MediaLibrary
- 🖼️ **Thumbnail Generation** - Automatic thumbnail generation with Intervention Image

Installation
------------

[](#installation)

### Option 1: Install from Packagist (Recommended)

[](#option-1-install-from-packagist-recommended)

```
composer require minemindmedia/laravel-mmmedia
```

### Option 2: Install directly from GitHub

[](#option-2-install-directly-from-github)

Add the repository to your `composer.json`:

```
{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/minemindmedia/laravel-mmmedia.git"
        }
    ]
}
```

Then install:

```
composer require minemindmedia/laravel-mmmedia:dev-main
```

Publish the configuration file:

```
php artisan vendor:publish --provider="Mmmedia\Media\MediaServiceProvider" --tag=media-config
```

Publish and run the migrations:

```
php artisan vendor:publish --provider="Mmmedia\Media\MediaServiceProvider" --tag=media-migrations
php artisan migrate
```

Quick Start
-----------

[](#quick-start)

1. **Add the trait to your model:**

```
use Mmmedia\Media\Support\HasMediaAttachments;

class Product extends Model {
    use HasMediaAttachments;
}
```

2. **Use MediaPicker in your Filament form:**

```
use Mmmedia\Media\Filament\Forms\Components\MediaPicker;

MediaPicker::make('featured_image_id')
    ->label('Featured Image')
    ->fieldKey('featured_image')
    ->multiple(false)
    ->allowUpload(true);
```

3. **Access the Media Library:**Visit your Filament admin panel and you'll see a new "Media" section where you can manage all media items.

Filament v4 Compatibility
-------------------------

[](#filament-v4-compatibility)

This package is **100% natively compatible** with Filament v4! No vendor patches required.

🎉 **Complete native Filament v4 support achieved in v1.1.3!**

> **Note**: If you're using a custom MediaItem model, make sure the `generateThumbnail()` method is public to avoid visibility conflicts.

### Using with Spatie MediaLibrary

[](#using-with-spatie-medialibrary)

If you're already using Spatie MediaLibrary, the MediaPicker will automatically detect and work with your existing media:

```
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class Product extends Model implements HasMedia
{
    use InteractsWithMedia;

    // MediaPicker will automatically work with your Spatie collections
}
```

### Using with Package's Media System

[](#using-with-packages-media-system)

If you prefer to use the package's built-in media system:

```
use Mmmedia\Media\Support\HasMediaAttachments;

class Product extends Model
{
    use HasMediaAttachments;
}
```

### Custom MediaItem Model

[](#custom-mediaitem-model)

If you need to customize the MediaItem model, you can create your own and disable automatic binding:

```
// In config/media.php
'allow_custom_model' => false,

// Or in your .env file
MEDIA_ALLOW_CUSTOM_MODEL=false
```

Then create your custom model:

```
use Mmmedia\Media\Support\MediaItemCompatibility;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

class MediaItem extends Model implements HasMedia
{
    use InteractsWithMedia, MediaItemCompatibility;

    // Your custom implementation
    public function getThumbnailUrlAttribute(): ?string
    {
        // Your custom thumbnail logic
        return $this->customThumbnailMethod();
    }
}
```

Configuration
-------------

[](#configuration)

The package configuration is located in `config/media.php`. Here are the key settings:

```
return [
    // Default disk for storing media files
    'disk' => env('MEDIA_DISK', 'public'),

    // Upload settings
    'upload' => [
        'max_file_size' => env('MEDIA_MAX_FILE_SIZE', 10240), // KB
        'max_files' => env('MEDIA_MAX_FILES', 10),
        'allowed_mimes' => [
            'image' => ['image/jpeg', 'image/png', 'image/gif', 'image/webp'],
            'video' => ['video/mp4', 'video/avi', 'video/mov'],
            'document' => ['application/pdf', 'application/msword'],
        ],
    ],

    // Storage paths
    'paths' => [
        'images' => 'media/images',
        'videos' => 'media/videos',
        'documents' => 'media/documents',
    ],
];
```

Usage
-----

[](#usage)

### 1. Add the Trait to Your Models

[](#1-add-the-trait-to-your-models)

Add the `HasMediaAttachments` trait to any model that needs media functionality:

```
