PHPackages                             yoelpc4/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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. yoelpc4/laravel-media

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

yoelpc4/laravel-media
=====================

Laravel Media manager.

v0.3.0(1y ago)112MITPHPPHP &gt;=7.2CI failing

Since Jul 28Pushed 1y ago1 watchersCompare

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

READMEChangelogDependencies (9)Versions (2)Used By (0)

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

[](#laravel-media)

[![Packagist](https://camo.githubusercontent.com/cb11b73da8b3b8f156aba783e030a6ab9fdf059d068f8f3233c9c547f370babd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796f656c7063342f6c61726176656c2d6d656469612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yoelpc4/laravel-media)[![Downloads](https://camo.githubusercontent.com/dd941ee9b3808a4021ce6aab2cd8ca325a34c5e7d0ca8bd6b67f6d38673347f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796f656c7063342f6c61726176656c2d6d656469612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yoelpc4/laravel-media)[![Build](https://camo.githubusercontent.com/4c3e66721fa16b92c62a6d3ec6cf485a5508ec58aa4c4b37ac26104b19176f8d/68747470733a2f2f7472617669732d63692e636f6d2f796f656c7063342f6c61726176656c2d6d656469612e7376673f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://travis-ci.com/yoelpc4/laravel-media)[![Code Coverage](https://camo.githubusercontent.com/9ebfb046a9494c6fbb38bc90917d166dbd154c909d14f262985b350f9e0b2c4e/68747470733a2f2f636f6465636f762e696f2f67682f796f656c7063342f6c61726176656c2d6d656469612f6272616e63682f6d61737465722f67726170682f62616467652e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/yoelpc4/laravel-media)[![Software License](https://camo.githubusercontent.com/9256f0261824e672545622d8dbea17f80156e4a1ac984eed4a221d7a1cd70bc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f796f656c7063342f6c61726176656c2d6d656469612e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Contributor Covenant](https://camo.githubusercontent.com/2757a9db291c5ceda172e31d4fa5f3c4048a6e6257ee0b7113f80de277074b91/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f436f6e7472696275746f72253230436f76656e616e742d76322e3025323061646f707465642d6666363962342e737667)](CODE_OF_CONDUCT.md)

*Laravel Media manager.*

Requirement
-----------

[](#requirement)

- [Laravel](https://laravel.com)

Install
-------

[](#install)

Require this package with composer via command:

```
composer require yoelpc4/laravel-media
```

Package Publication
-------------------

[](#package-publication)

Publish package configuration via command:

```
php artisan vendor:publish --provider="Yoelpc4\LaravelMedia\MediaServiceProvider" --tag=config
```

Publish package migrations via command:

```
php artisan vendor:publish --provider="Yoelpc4\LaravelMedia\MediaServiceProvider" --tag=migrations
```

Publish package resources via command:

```
php artisan vendor:publish --provider="Yoelpc4\LaravelMedia\MediaServiceProvider" --tag=resources
```

Configure
---------

[](#configure)

### Image Optimizers

[](#image-optimizers)

By default, all images added to the media will be optimized according to `image_optimizers` on the media config. For more information visit .

### Media Model

[](#media-model)

Customize media model by extending `\Yoelpc4\LaravelMedia\Models\Media`, then register your model on `model` option.

### Media Observer

[](#media-observer)

Customize media observer by extending `\Yoelpc4\LaravelMedia\Observers\MediaObserver`, then register your observer on `observer` option.

### Versioned URL

[](#versioned-url)

Generate media URL with version on query params i.e:  by setting `versioned_url` option to true.

Mediable Model
--------------

[](#mediable-model)

### Mediable Contract and InteractsWithMedia Concern

[](#mediable-contract-and-interactswithmedia-concern)

The model that has media must implement `\Yoelpc4\LaravelMedia\Contracts\Mediable` interface and use `\Yoelpc4\LaravelMedia\Concerns\InteractsWithMedia` trait.

Example Mediable Contract and InteractsWithMedia Concern usage with profileImage relationship on User model

```
class User extends \Illuminate\Database\Eloquent\Model implements \Yoelpc4\LaravelMedia\Contracts\Mediable {
    use \Yoelpc4\LaravelMedia\Concerns\InteractsWithMedia;

    /**
     * User morph one profile image
     *
     * @return \Illuminate\Database\Eloquent\Relations\MorphOne
     */
    public function profileImage()
    {
        return $this->morphOne(\Yoelpc4\LaravelMedia\Models\Media::class, 'mediable')->whereGroup('profile image');
    }
}
```

### Media Group Registration

[](#media-group-registration)

Example register the media group on your mediable model on Project model

```
/**
 * @inheritDoc
 */
public function registerMediaGroups()
{
    $this->addMediaGroup('contract document')
        ->setMimeTypes('application/pdf')
        ->setMaxFileLimit(3);
}
```

### Media Conversion Registration

[](#media-conversion-registration)

Example register the media conversion on media group registration on User model

```
/**
 * @inheritDoc
 */
public function registerMediaGroups()
{
    $this->addMediaGroup('profile image')
        ->setMimeTypes(['image/jpeg', 'image/png'])
        ->setMaxFileLimit(1)
        ->registerMediaConversions(function () {
            $this->addMediaConversion('square-thumb')
                ->width(160)
                ->height(160);
        });
}
```

Media Group
-----------

[](#media-group)

The media group has name, mime types, max file size, max file limit &amp; media conversions registration properties. It consists of one file or many files. The mime types, max file size, max file limit properties will be used on validation when adding file to the media. The default media group has empty array mime types, 2MB max file size, &amp; null max file limit.

If media group has max file limit with integer data type (other than null), this package will keep last of max file limit file(s) on disk and remove the other file(s). For example User model has profile image media group with max file limit 1, and we have an user id 1 has a profile image as media id 1 on database. If we try to upload a profile image on user id 1, then media id 1 and old profile image will be deleted and user id 1 ends up with media id 2 and new profile image.

Media Conversion
----------------

[](#media-conversion)

The media conversion has name, manipulations, and should be performed on media group properties. It is intended to the media with file type image. You can call `\Spatie\Image\Manipulations` methods on media conversion registration because it has `__call` magic method, the proxied method call will be registered as it's manipulations.

Add Media File to Mediable
--------------------------

[](#add-media-file-to-mediable)

### Add Media File from Path

[](#add-media-file-from-path)

Example add a media file from storage path to the first User model on database

```
try {
$path = storage_path('avatar.jpg');

$media = User::first()->addFile($path)->toMediaGroup('profile image');
} catch (\Illuminate\Contracts\Filesystem\FileNotFoundException $e) {
    throw $e;
} catch (\Illuminate\Validation\ValidationException $e) {
    throw $e;
} catch (\Spatie\Image\Exceptions\InvalidImageDriver $e) {
    throw $e;
}
```

### Add Media File from Uploaded File

[](#add-media-file-from-uploaded-file)

Example add a media file from `\Illuminate\Http\UploadedFile` to the unsaved Project model

```
try {
$uploadedFile = request()->file('file');

$media = (new Project)->addFile($uploadedFile)->toMediaGroup('contract document');
} catch (\Illuminate\Contracts\Filesystem\FileNotFoundException $e) {
    throw $e;
} catch (\Illuminate\Validation\ValidationException $e) {
    throw $e;
} catch (\Spatie\Image\Exceptions\InvalidImageDriver $e) {
    throw $e;
}
```

Media URL Generation
--------------------

[](#media-url-generation)

### Get Media URL

[](#get-media-url)

Example get media url on media

```
$url = Media::first()->getMediaUrl();
```

### Get Media Conversion URL

[](#get-media-conversion-url)

Example get media conversion url on related media

```
$url = User::first()->profileImage->getMediaConversionUrl('square-thumb');
```

If the media doesn't have the specified media conversion name it'll return null.

Difference From [spatie/laravel-medialibrary](https://github.com/spatie/laravel-medialibrary)
---------------------------------------------------------------------------------------------

[](#difference-from-spatielaravel-medialibrary)

### Media Group vs Media Collection

[](#media-group-vs-media-collection)

laravel-media use media group as the term of similar media type, while laravel-medialibrary use media collection as the term.

### Mandatory Media Group

[](#mandatory-media-group)

laravel-media require you to add file to the named media group on mediable model. While laravel-medialibrary offers flexibility to omit media group name and gives you "default" as media group name.

### Validation Exception

[](#validation-exception)

laravel-media always perform validation based on registered media group's mime types and max file size, the `\Illuminate\Validation\ValidationException` will be thrown when validation is unmet. On the other hand laravel-medialibrary throws `\Spatie\MediaLibrary\MediaCollections\Exceptions\FileUnacceptableForCollection` instead of `\Illuminate\Validation\ValidationException`.

### Add File to Unsaved Mediable Model

[](#add-file-to-unsaved-mediable-model)

laravel-media allows you to add media file to the unsaved mediable model. While laravel-medialibrary expects every media must be attached to the saved mediable model.

For more information see issues here:

- [spatie/laravel-medialibrary#343](https://github.com/spatie/laravel-medialibrary/issues/343)
- [spatie/laravel-medialibrary#1060](https://github.com/spatie/laravel-medialibrary/issues/1060)
- [spatie/laravel-medialibrary#1384](https://github.com/spatie/laravel-medialibrary/issues/1384)
- [spatie/laravel-medialibrary#1423](https://github.com/spatie/laravel-medialibrary/issues/1423)
- [spatie/laravel-medialibrary#1444](https://github.com/spatie/laravel-medialibrary/issues/1444)

Also the pull request here:

- [spatie/laravel-medialibrary#1443](https://github.com/spatie/laravel-medialibrary/pull/1443)

### File source

[](#file-source)

laravel-media only allows you to add file from disk path and uploaded file. While laravel-media allows you to add file from disk path, remote file, uploaded file, symfony file, temporary upload, url, &amp; request.

### Comprehensive vs Narrow Solution

[](#comprehensive-vs-narrow-solution)

laravel-media offers you narrow solution with limited features for specific requirements (validation exception, unsaved mediable model, &amp; simple file source). While laravel-medialibrary offers you comprehensive solution with rich features and battle tested. So consider carefully prior to install this package.

License
-------

[](#license)

The Laravel Media is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

705d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e021c8ceb146b0532ac3d225635988b51de61dac3e95933907859b96dc12bab6?d=identicon)[yoelpc4](/maintainers/yoelpc4)

---

Top Contributors

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

---

Tags

laravelimagegdimagickconversionaudiovideomediadocument

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k43.2M631](/packages/spatie-laravel-medialibrary)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)

PHPackages © 2026

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