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

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

r94ever/laravel-media
=====================

v12.0(7mo ago)0471MITPHPPHP ^8.2CI passing

Since Jun 12Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/r94ever/laravel-media)[ Packagist](https://packagist.org/packages/r94ever/laravel-media)[ RSS](/packages/r94ever-laravel-media/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

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

[](#laravel-media)

An easy solution to attach files to your eloquent models, with image manipulation built in!

[![Packagist Version](https://camo.githubusercontent.com/720ebf7f7702de7707903144d1a004177330e85ca245b3d2cceb740c57162054/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f723934657665722f6c61726176656c2d6d656469612e737667)](https://packagist.org/packages/r94ever/laravel-media)[![Run tests](https://github.com/r94ever/laravel-media/actions/workflows/run-tests.yml/badge.svg)](https://github.com/r94ever/laravel-media/actions/workflows/run-tests.yml)[![License](https://camo.githubusercontent.com/53f53690dbcc543f683fda3e10c5fd2b4aa7251d80b8714052f8e781c8d9cb11/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f723934657665722f6c61726176656c2d6d656469612e737667)](https://github.com/r94ever/laravel-media/blob/master/LICENSE.md)

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

[](#installation)

You can install the package via composer:

```
composer require r94ever/laravel-media
```

Once installed, you should publish the provided assets to create the necessary migration and config files.

```
php artisan vendor:publish --provider="R94ever\Media\MediaServiceProvider"
```

Key concepts
------------

[](#key-concepts)

There are a few key concepts that should be understood before continuing:

- Media can be any type of file, from a jpeg to a zip file. You should specify any file restrictions in your application's validation logic before you attempt to upload a file.
- Media is uploaded as its own entity. It does not belong to another model in the system when it's created, so items can be managed independently (which makes it the perfect engine for a media manager).
- Media must be attached to a model for an association to be made.
- Media items are bound to "groups". This makes it easy to associate multiple types of media to a model. For example, a model might have an "images" group and a "documents" group.
- You can manipulate images using conversions. You can specify conversions to be performed when a media item is associated to a model. For example, you can register a "thumbnail" conversion to run when images are attached to a model's "gallery" group.
- Conversions are registered globally. This means that they can be reused across your application, i.e a Post and a User can have the same sized thumbnail without having to register the same conversion twice.

Usage
-----

[](#usage)

### Upload media

[](#upload-media)

You should use the `R94ever\Media\MediaUploader` class to handle file uploads.

By default, this class will update files to the disk specified in the media config. It saves them as a sanitised version of their original file name, and creates a media record in the database with the file's details.

You can also customise certain properties of the file before it's uploaded.

```
$file = $request->file('file');

// Default usage
$media = MediaUploader::fromFile($file)->upload();

// Custom usage
$media = MediaUploader::fromFile($file)
    ->useFileName('custom-file-name.jpeg')
    ->useName('Custom media name')
    ->upload();
```

### Associate media with a model

[](#associate-media-with-a-model)

In order to associate a media item with a model, you must first include the `R94ever\Media\HasMedia` trait.

```
class Post extends Model
{
    use HasMedia;
}
```

This trait will setup the relationship between your model and the media model. It's primary purpose is to provide a fluent api for attaching and retrieving media.

Once included, you can attach media to the model as demonstrated below. The first parameter of the attach media method can either be a media model instance, an id, or an iterable list of models / ids.

```
$post = Post::first();

// To the default group
$post->attachMedia($media);

// To a custom group
$post->attachMedia($media, 'custom-group');
```

### Disassociate media from a model

[](#disassociate-media-from-a-model)

To disassociate media from a model, you should call the provided `detachMedia` method.

```
// Detach all the media
$post->detachMedia();

// Detach the specified media
$post->detachMedia($media);

// Detach all the media in a group
$post->clearMediaGroup('your-group');
```

If you want to delete a media item, you should do it the same way you would for any other model in your application.

```
Media::first()->delete();
```

Doing so will delete the file from your filesystem, and also remove any association between the media item and your application's models.

### Retrieve media

[](#retrieve-media)

Another feature of the `HasMedia` trait is the ability to retrieve media.

```
// All media in the default group
$post->getMedia();

// All media in a custom group
$post->getMedia('custom-group');

// First media item in the default group
$post->getFirstMedia();

// First media item in a custom group
$post->getFirstMedia('custom-group');
```

As well as retrieve media items, you can also retrieve attributes of the media model directly from your model.

```
// Url of the first media item in the default group
$post->getFirstMediaUrl();

// Url of the first media item in a custom group
$post->getFirstMediaUrl('custom-group');
```

### Manipulate Images

[](#manipulate-images)

This package provides a fluent api to manipulate images. You can specify a model to perform "conversions" when media is attached to a group. It uses the familiar `intervention/image` library under the hood, so images can be manipulated using all of the library's provided options.

To get started, you should first register a conversion in one of your application's service providers:

```
use Intervention\Image\Image;
use R94ever\Media\Facades\Conversion;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Conversion::register('thumb', function (Image $image) {
            return $image->fit(64, 64);
        });
    }
}
```

Once you've registered a conversion, you should configure a media group to perform the conversion when media is attached to your model.

```
class Post extends Model
{
    use HasMedia;

    public function registerMediaGroups()
    {
        $this->addMediaGroup('gallery')
             ->performConversions('thumb');
    }
}
```

Now when a media item is attached to the "gallery" group, a converted image will be generated. You can get the url of the converted image as demonstrated below:

```
// The thumbnail of the first image in the gallery group
$post->getFirstMediaUrl('gallery', 'thumb');
```

Why use this package?
---------------------

[](#why-use-this-package)

There are already packages that exist to solve a similar problem to the one that this package was built to achieve.

The most popular of which are:

- [Spatie's Laravel MediaLibrary](https://github.com/spatie/laravel-medialibrary)
- [Plank's Laravel Mediable](https://github.com/plank/laravel-mediable)

There are a few key differences between this package and the ones listed above. Our package was built to power media managers, and make it easy to perform image manipulations. This is better represented by the comparison table below:

ComparisonSpatiePlankR94ever**Relationship type**One to manyMany to manyMany to many**Provides image manipulation**YesNoYes**Definition of manipulations**Specific to a model-Global registryLicense
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance63

Regular maintenance activity

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~603 days

Total

3

Last Release

225d ago

Major Versions

9.0 → 10.02025-06-14

10.0 → v12.02025-09-30

PHP version history (2 changes)9.0PHP ^8.0.1

v12.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/2150c2a2255f67e95fd6faba67aa5af3777b17c7d98ba309e879e8b7fd38efb9?d=identicon)[r94ever](/maintainers/r94ever)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[rahulhaque/laravel-filepond

Use FilePond the Laravel way

261114.4k2](/packages/rahulhaque-laravel-filepond)

PHPackages © 2026

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