PHPackages                             ogrre/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. [Image &amp; Media](/categories/media)
4. /
5. ogrre/laravel-media

ActiveLibrary[Image &amp; Media](/categories/media)

ogrre/laravel-media
===================

Package to manage media easy in laravel

1.0.3(2y ago)136MITPHPPHP ^7.3|^8.0|^8.1

Since Jan 9Pushed 2y agoCompare

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

READMEChangelog (7)Dependencies (2)Versions (8)Used By (0)

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

[](#laravel-media)

[![Packagist Version](https://camo.githubusercontent.com/7f3b541bcbedf315a32d924bb938b26a142267f4a56611f3d820080e8a0e5c2e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f677272652f6c61726176656c2d6d65646961)](https://camo.githubusercontent.com/7f3b541bcbedf315a32d924bb938b26a142267f4a56611f3d820080e8a0e5c2e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f677272652f6c61726176656c2d6d65646961)[![GitHub License](https://camo.githubusercontent.com/1d99486e149a78f29303bca6b3ab598647fb214bb5f7a4051ba9140d2c8f432d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f30677272652f6c61726176656c2d6d65646961)](https://camo.githubusercontent.com/1d99486e149a78f29303bca6b3ab598647fb214bb5f7a4051ba9140d2c8f432d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f30677272652f6c61726176656c2d6d65646961)[![Packagist Downloads](https://camo.githubusercontent.com/cc0e025870aacefec9867c4e6518d79c1acd7bb9842601cfb0af55f3e1722ba0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f677272652f6c61726176656c2d6d65646961)](https://camo.githubusercontent.com/cc0e025870aacefec9867c4e6518d79c1acd7bb9842601cfb0af55f3e1722ba0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f677272652f6c61726176656c2d6d65646961)

### Introduction

[](#introduction)

This Laravel package allows you to associate media with models to be able to manage your files more easily.

This is my first package, do not hesitate to report problems, I may not have thought of everything

### Documentation, Installation, and Usage Instructions

[](#documentation-installation-and-usage-instructions)

See the [documentation](https://jbloup.dev) for detailed installation and usage instructions.

#### Installation

[](#installation)

This package publishes a config/media.php file. If you already have a file by that name, you must rename or remove it.

You can install the package via composer:

```
composer require ogrre/laravel-media
```

The service provider is automatically registered in app.php, but you can add the service provider manually in config/app.php

```
# config/app.php

'providers' => [
    // ...
    Ogrre\Media\MediaServiceProvider::class,
];

```

You need to start the migration for this to work well, so make sure you have **media.php** in the config folder as well as the **create\_media\_tables.php** file in the **database/migrations** folder of your application.

If this is not the case run the command

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

### Configuration

[](#configuration)

By default, the **Media** class will take as an attribute mime\_type and disk the values of the media configuration file. You can change there values in **config/media.php**.

### Usages

[](#usages)

This package works with two classes, the class **Media** and the class **MediaFile**, to manage the files it is necessary to associate a model, such as a user for example, with a media, such as *avatar* for example. It is therefore necessary to create the *avatar* media first.

#### Media

[](#media)

The Media class works as an eloquent model of Laravel create, update,... etc

You can create the media as follows

```
Media::create(['name' => "new_media"]);

```

In this situation, the media will be created with the default attributes corresponding to the configuration file.

Otherwise, you can do it in the classic way

```
Media::create(['name' => "pdf_media", "mime_type" => "pdf", "disk" => "public"]);

```

Once the **Media** are created, you can associate them with a model that has the trait *hasMedia*.

For exemple *User* model

```
class User extends Authenticatable
{
    use HasFactory, HasMedia;
    ...

```

To associate Media at *User* model

```
$user = User::find(1)

// assign media by id
$user->assignMedia(1);

// assign media by name
$user->assignMedia("avatar);

// assign multipe media
$user->assignMedia(['avatar', 'new_media']);

// assign media with media object
$media = Media::find(1);
$user->assignMedia($media);

```

You can check if model has media

```
// return false if user hasn't this media
$user->hasMedia($media);

```

#### MediaFile

[](#mediafile)

When a media is associated with a model, you can add a file that will be associated with the model as well as the media, it works like a classic crud.

```
public function upload(Request $request)
{
    $file = $request->file('avatar');

    $user = User::find(1);

    $user->addMediaFile($file, 'avatar');
}

```

*getMediaFile* function will return the *MediaFile* model with all the useful data about the file.

```
$user->getMediaFile('avatar');

```

*updateMediaFile* function will delete the previously saved file and save a new one to the media disk.

```
$user->updateMediaFile($file, $media);

```

*deleteMediaFile* will delete the *Mediafile* associated to Model as well as file.

```
$user->deleteMediaFile(1);

```

Contributing
============

[](#contributing)

Contributions are welcome and will be fully credited. I accept contributions via Pull Requests on Github.

Support me
==========

[](#support-me)

[![Buy Me A Coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/0grre)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

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

Recently: every ~79 days

Total

7

Last Release

883d ago

Major Versions

0.0.3 → 1.0.02023-01-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d4c871c07ee63285d919d302d5789af131cf66cea09ad55802c95a1d536c01f?d=identicon)[0grre](/maintainers/0grre)

---

Top Contributors

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

---

Tags

composer-librarylaravellibrarymediaphp

### Embed Badge

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

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

###  Alternatives

[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M102](/packages/intervention-image-laravel)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[spatie/laravel-og-image

Generate OG images for your Laravel app

305.2k](/packages/spatie-laravel-og-image)

PHPackages © 2026

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