PHPackages                             nh/mediable - 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. nh/mediable

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

nh/mediable
===========

Upload and attach media to a model

1.6.8(2y ago)02781MITPHP

Since Apr 22Pushed 2y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (22)Used By (1)

Installation
============

[](#installation)

Install the package via composer:

```
composer require nh/mediable

```

Publish the config and the Media model:

```
php artisan vendor:publish --tag=mediable

```

If you need to publish the database you can use:

```
php artisan vendor:publish --tag=mediable-database

```

To make a model mediable, add the **Mediable** trait to your model:

```
use Nh\Mediable\Traits\Mediable;

use Mediable;

```

You can retrieve the media (order by a position) of a model:

```
$model->media;

```

Or you can retrieve the first media of a model:

```
$model->firstMedia;

```

Retrieve all media by a type:

```
$model->mediaByType('picture');

```

You can check if a model has some media:

```
$model->hasMedia(); // Check if there is some media
$model->hasMedia(true); // Check if there is some media, even soft deleted ones
$model->hasMedia(false,'picture'); // Check if there is some media of type "picture"

```

If you need to resize the picture media (JPEG/PNG), add the sizes in the config **mediable.php** at **'sizes'**:

```
'posts' => [
  'fit'    => null,
  'height' => [100,200],
  'width'  => 400,800
]

```

If you need to add a watermark you can activate the functionnality in the config **mediable.php**, add the sizes in the config **mediable.php** at **'sizes'**:

```
'watermark' => [
    'enable' => true, // Enable the watermark
    'src' => 'images/watermark.png', // Must be in public folder
    'position' => [
      'name' => 'bottom-right',
      'x' => 5,
      'y' => 5
     ]
],

```

By default the media are upload in the public disk, but you can change this in the config **mediable.php**.

The media are saved in:

- A folder with the model classname in plural *(exemple: App\\Post =&gt; posts)*
- A folder with the media format name in plural *(exemple: 42.jpg =&gt; images)*
- For the images, a folder with the resize value *(exemple: 42.jpg which is resized with a 100px height =&gt; h-100)*

Views
-----

[](#views)

Add a media
-----------

[](#add-a-media)

The names of the inputs must be: **media\_to\_add\[KEY\]\[name\]** and **media\_to\_add\[KEY\]\[file\]** and in option you can add **media\_to\_add\[KEY\]\[position\]**

```
Name of the media

File to upload

```

Edit a media
------------

[](#edit-a-media)

The name of the input must be: **media\_to\_update\[KEY\]\[name\]** and in option you can add **media\_to\_update\[KEY\]\[position\]**

```
Name of the media

```

Delete a media
--------------

[](#delete-a-media)

The name of the input must be: **media\_to\_delete\[\]** and the value must be the ID

```

```

Model
=====

[](#model)

Attributes
----------

[](#attributes)

You can retrieve the filename of a media *Return: 42.jpg*

```
$media->filename

```

You can retrieve the base folder of a media *Return: posts*

```
$media->base_folder

```

You can retrieve the folder of a media *Return: posts/images*

```
$media->folder

```

You can retrieve the format of a media *The format is defined by the extension, exemple a .jpg will return 'image'*

```
$media->format

```

You can retrieve the default url of a media *Return: posts/images/42.jpg*

```
$media->url

```

You can retrieve the url of a the thumbnail of a media **(Only if the format is 'image')***Return: posts/images/thumbnails/42.jpg*

```
$media->thumbnail

```

Function
--------

[](#function)

You can retrieve the url of a media, and you can add a subfolder. *Exemple: 42.jpg which is resized with a 100px height =&gt; 'posts/images/h-100/42.jpg'*

```
$media->getUrl('h-100')

```

You can retrieve the absolute url of a media from the server, and you can add a subfolder. *Exemple: 42.jpg which is resized with a 100px height =&gt; '/Users/YOURUSERNAME/Web/MYPROJECT/public/storage/FOLDER/images/SUBFOLDER/42.png'*

```
$media->getAbsoluteUrl('h-100')

```

You can retrieve the file of a media, and you can add a subfolder. *Exemple: 42.jpg which is resized with a 100px height =&gt; 'posts/images/h-100/42.jpg'*

```
$media->getFile('h-100')

```

Events
======

[](#events)

You can use the **MediaEvent** for dispatch events that happen to the media. *You can pass a name, the parent model, the media model (or null) and the number of media affected*

```
MediaEvent::dispatch('my-event', $model, $media, 1);

```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

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

Recently: every ~125 days

Total

21

Last Release

1089d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/47361520c40f781d7d5b39e26b3194800a35e89c4819c220ea3eaaaa907c34ec?d=identicon)[NatachaH](/maintainers/NatachaH)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/nh-mediable/health.svg)

```
[![Health](https://phpackages.com/badges/nh-mediable/health.svg)](https://phpackages.com/packages/nh-mediable)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[barryvdh/elfinder-flysystem-driver

A Flysystem Driver for elFinder

1864.7M31](/packages/barryvdh-elfinder-flysystem-driver)[itskodinger/midia

Simple Media manager for your Laravel project

1415.8k](/packages/itskodinger-midia)[jeremytubbs/deepzoom

Deepzoom Tile Generator for OpenSeadragon

5018.7k2](/packages/jeremytubbs-deepzoom)[farhanshares/laravel-mediaman

MediaMan - The most elegant &amp; powerful media management package for Laravel!

293.7k](/packages/farhanshares-laravel-mediaman)[xefi/faker-php-images

Faker extension to generate images

402.6k](/packages/xefi-faker-php-images)

PHPackages © 2026

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