PHPackages                             rdcstarr/laravel-media - 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. rdcstarr/laravel-media

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

rdcstarr/laravel-media
======================

Flexible media management for Laravel with auto-optimization, multi-format images (WebP/AVIF), video support, and dynamic collections.

v1.1.9(3mo ago)020MITPHPPHP ^8.3

Since Nov 24Pushed 3mo agoCompare

[ Source](https://github.com/rdcstarr/laravel-media)[ Packagist](https://packagist.org/packages/rdcstarr/laravel-media)[ Docs](https://github.com/rdcstarr/laravel-media)[ RSS](/packages/rdcstarr-laravel-media/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (18)Versions (20)Used By (0)

Laravel Media
=============

[](#laravel-media)

[![Latest Version on Packagist](https://camo.githubusercontent.com/062a5fb392bc1c9d62247c8ded690d8f5c0e6f7f0b433be254a41d556f67fb40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72646373746172722f6c61726176656c2d6d656469612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rdcstarr/laravel-media)[![GitHub Tests Action Status](https://camo.githubusercontent.com/8643f0a7f9743f71c91f472538f4ed47ceecedb6aa1c2678c772a8be8d554e3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72646373746172722f6c61726176656c2d6d656469612f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/rdcstarr/laravel-media/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/691b961e54b48a2aaf3a7ac57c1d37539f02111e30ee52a25ada7b521e0baf0d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72646373746172722f6c61726176656c2d6d656469612f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/rdcstarr/laravel-media/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/fa9391748a8b5fcd248eb8b823c6477620fd90c4e8dd711ac6064c52fe7dcac2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72646373746172722f6c61726176656c2d6d656469612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rdcstarr/laravel-media)

A flexible and powerful media management package for Laravel that handles images, videos, audio files, and documents with ease. Features automatic image optimization, multiple format support (WebP, AVIF), dynamic collections, and seamless Eloquent integration.

Features
--------

[](#features)

- 🖼️ **Image Processing**: Automatic resizing, cropping, and format conversion (WebP, AVIF, PNG, JPG)
- 📁 **Multiple File Types**: Support for images, videos, audio, and generic files
- 🔗 **Model-Centric Design**: Tightly integrated with Eloquent models
- 📦 **Collections**: Organize media files into named collections
- 🎯 **Flexible Configuration**: Per-collection settings for disk, path, dimensions, and more
- 🗑️ **Automatic Cleanup**: Files are deleted when models or media records are removed
- 🔄 **Soft Delete Support**: Respects soft deletes on parent models
- 📤 **URL Support**: Upload files directly from URLs
- 🏷️ **Metadata**: Store custom metadata with each media file
- ⚡ **Events**: Listen to media created, updated, and deleted events

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

[](#installation)

You can install the package via composer:

```
composer require rdcstarr/laravel-media
```

### Automatic Installation (Recommended)

[](#automatic-installation-recommended)

Run the install command to publish and run the migrations:

```
php artisan media:install
```

### Manual Installation

[](#manual-installation)

Alternatively, you can install manually:

1. Publish the migrations:

```
php artisan vendor:publish --tag=media-migrations
```

2. Run the migrations:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Setup Model

[](#setup-model)

```
use Rdcstarr\Media\Traits\HasMedia;
use Rdcstarr\Media\Enums\{MediaType, ImageExtension};

class Product extends Model
{
    use HasMedia;

    public function mediaCollection(): array
    {
        return [
            'thumbnail' => [
                'type' => MediaType::Image,
                'width' => 300,
                'height' => 300,
                'extensions' => [ImageExtension::WEBP => 90, ImageExtension::JPG => 85],
            ],
            'gallery' => [
                'type' => MediaType::Image,
                'width' => 1200,
                'extensions' => [ImageExtension::WEBP => 90, ImageExtension::AVIF => 80],
            ],
        ];
    }
}
```

### Upload &amp; Retrieve

[](#upload--retrieve)

```
// Upload
$product->attachMedia()->file($request->file('image'))->addToCollection('gallery');
$product->attachMedia()->file('https://example.com/image.jpg')->replaceExisting()->addToCollection('thumbnail');

// Retrieve
$url = $product->getMediaUrl('thumbnail', 'webp');
$product->getMediaThumbnailUrl('webp');  // Magic method
$product->clearMediaCollection('gallery', ['jpg']);  // Delete
```

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

[](#configuration)

### Collection Options

[](#collection-options)

```
[
    'type' => MediaType::Image,           // Media type (Image|Video|Audio|File)
    'disk' => 'public',                   // Storage disk
    'path' => '{model}/{collection}',     // Path with placeholders: {ulid}, {uuid}, {model}, {collection}
    'name' => '{ulid}',                   // Filename pattern
    'visibility' => 'public',             // File visibility
    'keep_original' => false,             // Keep original uploaded file (default: false)
    'width' => 1200,                      // Image width (px)
    'height' => 800,                      // Image height (px)
    'fit' => 'contain',                   // Fit mode (contain|cover|fill)
    'extensions' => [                     // Formats with quality
        ImageExtension::WEBP => 90,
        ImageExtension::AVIF => 80,
    ],
]
```

### Enums (Type-Safe)

[](#enums-type-safe)

- **MediaType**: `Image`, `Video`, `Audio`, `File`
- **ImageExtension**: `JPEG`, `JPG`, `PNG`, `WEBP`, `AVIF`, `GIF`, `SVG`, `BMP`, `TIFF`
- **VideoExtension**: `MP4`, `WEBM`, `OGG`, `AVI`, `MOV`, `WMV`, `FLV`, `MKV`, `M4V`
- **AudioExtension**: `MP3`, `WAV`, `OGG`, `M4A`, `AAC`, `FLAC`, `WMA`, `OPUS`

Events &amp; Architecture
-------------------------

[](#events--architecture)

**Events:** `MediaCreated`, `MediaUpdated`, `MediaDeleted`

**Model-centric design:** All operations require a model instance, ensuring type safety, clear ownership, and automatic cleanup of files when models or media are deleted.

🧪 Testing
---------

[](#-testing)

```
composer test
```

📖 Resources
-----------

[](#-resources)

- [Changelog](CHANGELOG.md) for more information on what has changed recently. ✍️

👥 Credits
---------

[](#-credits)

- [Rdcstarr](https://github.com/rdcstarr) 🙌

📜 License
---------

[](#-license)

- [License](LICENSE.md) for more information. ⚖️

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance81

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Recently: every ~30 days

Total

19

Last Release

100d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/42062586?v=4)[rdcstarr](/maintainers/rdcstarr)[@rdcstarr](https://github.com/rdcstarr)

---

Top Contributors

[![rdcstarr](https://avatars.githubusercontent.com/u/42062586?v=4)](https://github.com/rdcstarr "rdcstarr (19 commits)")

---

Tags

laravellaravel-mediaRdcstarr

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/rdcstarr-laravel-media/health.svg)

```
[![Health](https://phpackages.com/badges/rdcstarr-laravel-media/health.svg)](https://phpackages.com/packages/rdcstarr-laravel-media)
```

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[finller/laravel-media

A flexible media library for Laravel

472.1k](/packages/finller-laravel-media)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
