PHPackages                             themightysapien/medialibrary - 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. themightysapien/medialibrary

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

themightysapien/medialibrary
============================

Media Library on top of spatie media package. Helps to resuse uploaded media.

1.3.12(3y ago)130MITPHPPHP ^8.0|^8.1

Since Apr 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/themightysapien/laravelmedialibrary)[ Packagist](https://packagist.org/packages/themightysapien/medialibrary)[ Docs](https://github.com/themightysapien/medialibrary)[ RSS](/packages/themightysapien-medialibrary/feed)WikiDiscussions main Synced 3d ago

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

Reusable Library for Spatie Media Library
=========================================

[](#reusable-library-for-spatie-media-library)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9e13f86c548803edcc03bdf7b0e8032fa8be505334426a02db03981bdbe079e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7468656d696768747973617069656e2f6d656469616c6962726172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/themightysapien/medialibrary)[![Total Downloads](https://camo.githubusercontent.com/262307874c7691df5f73c90479dc9d518e4513bc171e21f813148ea21483d96b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7468656d696768747973617069656e2f6d656469616c6962726172792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/themightysapien/medialibrary)[![GitHub Actions](https://github.com/themightysapien/medialibrary/actions/workflows/main.yml/badge.svg)](https://github.com/themightysapien/medialibrary/actions/workflows/main.yml/badge.svg)

This packages adds a reusable library functionality on top of [Spatie Media Library](https://spatie.be/docs/laravel-medialibrary/v9/introduction) package.

### Features

[](#features)

- Add media to library
- Use media from library
- Add media through library
- Clear library

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

[](#installation)

You can install the package via composer:

```
composer require themightysapien/medialibrary
# publish config and migrations
php artisan vendor:publish --provider="Themightysapien\MediaLibrary\MediaLibraryServiceProvider" --tag="config" --tag="migrations"
# Check config files for any modifications then run
php artisan migrate
```

Prepare Your Model
------------------

[](#prepare-your-model)

Just add `InteractsWithMediaLibrary` trait on top of spatie's model setup.

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Themightysapien\MediaLibrary\Traits\InteractsWithMediaLibrary;

class YourModel extends Model implements HasMedia
{
    use InteractsWithMedia;
    use InteractsWithMediaLibrary;
}
```

Usage
-----

[](#usage)

#### Add Media to library

[](#add-media-to-library)

```
use Themightysapien\MediaLibrary\Facades\MediaLibrary;

$media = MediaLibrary::open($user_id)->addMedia($file);
```

#### Associate file for model through library.

[](#associate-file-for-model-through-library)

This will first add the file to library and then associate media to the model.

```
$model->addMediaThroughLibrary($file, $user_id)
// chain through any spatie's File Adder functions
->toMediaCollection();
```

#### Associate library media for model.

[](#associate-library-media-for-model)

```
$model->addMediaFromLibrary($media);
// chain through any spatie's File Adder functions
->toMediaCollection();
```

#### Clear Library

[](#clear-library)

```
use Themightysapien\MediaLibrary\Facades\MediaLibrary;

MediaLibrary::clear($user_id);
```

#### Get library media collection

[](#get-library-media-collection)

```
use Themightysapien\MediaLibrary\Facades\MediaLibrary;

// All Media
MediaLibrary::allMedia($user_id);

// Builder
MediaLibrary::query($user_id)->limit(5)->lastest()->get();
```

#### Get library media collection through api

[](#get-library-media-collection-through-api)

```
$response = $this->json('GET', '{PREFIX_FROM_CONFIG}/tsmedialibrary', [
    'name' => 'document', // matches file and name with document
    'type' => 'pdf', //matches mime type with pdf
    'sort_by' => 'created_at',
    'sort_type' => 'DESC',
    'per_page' => 10 // default set on config
]);

['items' => $mediaCollection, 'pagination' => $pagination] = $response;
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Anup Pokharel](https://github.com/themightysapien)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

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

Recently: every ~2 days

Total

7

Last Release

1124d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0b23d648de438858204fbfe985741871400a0084396a5f44a3e97522f7e7b110?d=identicon)[themightysapien](/maintainers/themightysapien)

---

Top Contributors

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

---

Tags

medialibrarythemightysapien

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/themightysapien-medialibrary/health.svg)

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

###  Alternatives

[illuminate/filesystem

The Illuminate Filesystem package.

16165.1M3.2k](/packages/illuminate-filesystem)

PHPackages © 2026

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