PHPackages                             moh-slimani/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. moh-slimani/media

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

moh-slimani/media
=================

A Media Model for laravel medialibrary

0.0.16(1y ago)142[3 PRs](https://github.com/slimani-dev/media/pulls)MITPHPPHP ^8.2CI passing

Since Feb 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/slimani-dev/media)[ Packagist](https://packagist.org/packages/moh-slimani/media)[ Docs](https://github.com/moh-slimani/media)[ GitHub Sponsors]()[ RSS](/packages/moh-slimani-media/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (14)Versions (22)Used By (0)

A Media Model for laravel medialibrary
======================================

[](#a-media-model-for-laravel-medialibrary)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7ef9c8c453da489e30817b938814454ccf57560718b0f616a2dce6f9222627ce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f682d736c696d616e692f6d656469612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/moh-slimani/media)[![GitHub Tests Action Status](https://camo.githubusercontent.com/9be365f27cded52a1a6a49e2211e5220e11cd43e5dad2ca1dcca9886e1e12afc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f682d736c696d616e692f6d656469612f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/moh-slimani/media/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d08ecce4eb548e193cfad1b1f3906a19a49a7982114e03956cfce6a6cab07c1e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d6f682d736c696d616e692f6d656469612f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/moh-slimani/media/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/a0611f357ddf8fa6ef6fca775e6228f4bcc9c0f69ce3c54c4e7955e648e4df15/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f682d736c696d616e692f6d656469612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/moh-slimani/media)

This package simplifies the integration of Spatie MediaLibrary by offering a streamlined approach to registering and managing media assets within Laravel applications, effortlessly cast media to a simple format, leveraging a path generator that enhances readability and organization. Seamlessly handle media registration while maintaining all functionalities of The MediaLibrary package.

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

[](#installation)

You can install the package via composer:

```
composer require moh-slimani/media
```

You must publish and run the migrations,this will add soft delete to the media model

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

change the media\_model in the media library config file

`config/media-library.php`

```
    ...
    /*
     * The fully qualified class name of the media model.
     */
    'media_model' => MohSlimani\Media\Models\Media::class,

    ...
```

**Optional :** you can change the path generator in the media library config file

```
    ...

    /*
     * The class that contains the strategy for determining a media file's path.
     */
    'path_generator' => MohSlimani\Media\Helpers\MediaPathGenerator::class,

    ...
```

Usage
-----

[](#usage)

```
use MohSlimani\Media\Traits\UseMediaModel
use MohSlimani\Media\Media
use Spatie\MediaLibrary\HasMedia;

class User extends Authenticatable implements HasMedia
{

    // you don't need to user InteractsWithMedia
    use HasApiTokens, HasFactory, Notifiable, UseMediaModel;

    /**
     * This array should contain the list of media keys to be registered.
     *
     * @var array $files
     * @example ['photo' => Media::SINGLE_FILE, 'files' => Media::MULTIPLE_FILES]
     */
    protected array $files = [
        'photo' => Media::SINGLE_FILE,
        'cv', // Media::SINGLE_FILE is the default
        'files' => Media::MULTIPLE_FILES
    ];

    ...
```

After that you can add files it like you used to using the `medialibrary` package

```
/** @var File $photo */
$user->addMedia($photo)->toMediaCollection('photo');

// Or use the included function
$user->addMediaFiles($photo, 'photo');
```

> the function addMediaFiles to simplify the process of adding media files to collections. This function allows you to add a single file to a specified collection and provides an option to keep or delete existing files in the collection. it will also generate a unique code based on current time to prepend to the file name You can find more information about this and other changes in the [CHANGELOG](CHANGELOG.md).

you can get the files like this

```
    $user->photo

    [
        "id" => 15,
        "name" => "IMG_7833",
        "url" => "http://media.test/storage/Users/1/photo/IMG_7833.jpg",
        "size" => 249686,
        "mime" => "image/jpeg",
        "type" => "image",
        "created_at" => Illuminate\Support\Carbon @1705898712 {#6527
          date: 2024-02-19 00:00:00.0 UTC (+00:00),
        },
        "updated_at" => Illuminate\Support\Carbon @1705898712 {#6782
          date: 2024-02-19 00:00:00.0 UTC (+00:00),
        },
    ]

```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Mohamed slimani](https://github.com/moh-slimani)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance66

Regular maintenance activity

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% 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 ~9 days

Recently: every ~29 days

Total

15

Last Release

682d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/889517e68d00e2c3709f76b1b944493e4303ff205c6a836108fb8dae6eb50cb6?d=identicon)[slimani](/maintainers/slimani)

---

Top Contributors

[![slimani-dev](https://avatars.githubusercontent.com/u/25089144?v=4)](https://github.com/slimani-dev "slimani-dev (27 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (7 commits)")

---

Tags

laravelmediaMohamed slimani

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/moh-slimani-media/health.svg)

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

###  Alternatives

[tomatophp/filament-media-manager

Manage your media files using spatie media library with easy to use GUI for FilamentPHP

14543.9k3](/packages/tomatophp-filament-media-manager)[silvanite/nova-field-cloudinary

A Laravel Nova Image Field with Flysystem Adapter for storing and retrieving media from Cloudinary

2972.0k3](/packages/silvanite-nova-field-cloudinary)[webplusm/gallery-json-media

a filament media storing in a Json field

196.0k](/packages/webplusm-gallery-json-media)[stepanenko3/nova-media-field

A Laravel Nova field for laravel-medilibrary.

1717.5k](/packages/stepanenko3-nova-media-field)[synchro/laravel-medialibrary-audio

Audio file thumbnail generator for Spatie's Laravel Media Library

292.4k](/packages/synchro-laravel-medialibrary-audio)[okipa/laravel-medialibrary-ext

Extra features for spatie/laravel-medialibrary package.

1011.2k](/packages/okipa-laravel-medialibrary-ext)

PHPackages © 2026

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