PHPackages                             anisaronno/laravel-media-gallery - 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. anisaronno/laravel-media-gallery

Abandoned → 126096Library[Image &amp; Media](/categories/media)

anisaronno/laravel-media-gallery
================================

Laravel Media Gallery

0.6.0(2y ago)03121MITPHPPHP ^7.4|^8.0

Since Oct 12Pushed 2y ago1 watchersCompare

[ Source](https://github.com/anisAronno/laravel-media-gallery)[ Packagist](https://packagist.org/packages/anisaronno/laravel-media-gallery)[ Docs](https://github.com/anisAronno/laravel-media-media)[ RSS](/packages/anisaronno-laravel-media-gallery/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (13)Used By (1)

Laravel Media Gallery
=====================

[](#laravel-media-gallery)

Table of Contents
-----------------

[](#table-of-contents)

- [Laravel Media Gallery](#laravel-media-gallery)
    - [Table of Contents](#table-of-contents)
    - [Introduction](#introduction)
    - [Installation](#installation)
    - [Publish Migration and Config](#publish-migration-and-config)
        - [Publish Migration, Config](#publish-migration-config)
    - [Uses](#uses)
        - [Eloquent Factories Relation Mapping](#eloquent-factories-relation-mapping)
        - [Retrieve media by owner](#retrieve-media-by-owner)
        - [Authentication and Configuration](#authentication-and-configuration)
            - [Customizing Authentication Guard:](#customizing-authentication-guard)
            - [Restricting Media Viewing:](#restricting-media-viewing)
            - [Defining Gate for Managing Media:](#defining-gate-for-managing-media)
            - [Cache Expiry Time:](#cache-expiry-time)
    - [Use Media with Relational Model](#use-media-with-relational-model)
    - [Working with Single or Featured Media](#working-with-single-or-featured-media)
    - [Helper Methods](#helper-methods)
    - [API Route for Media/Media](#api-route-for-mediamedia)
    - [Fetch Media/Media from Relational Model](#fetch-mediamedia-from-relational-model)
    - [Contribution Guide](#contribution-guide)
    - [License](#license)

Introduction
------------

[](#introduction)

The Laravel Media Gallery simplifies media and media file management in your Laravel project. This README provides installation instructions, usage examples, and additional information.

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

[](#installation)

To get started, install the package using Composer:

```
composer require anisaronno/laravel-media-gallery
```

Publish Migration and Config
----------------------------

[](#publish-migration-and-config)

For media library features, follow these steps:

### Publish Migration, Config

[](#publish-migration-config)

Publish the migration, factory and seeder file:

```
php artisan vendor:publish --tag=media-migration
```

Publish the Config file:

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

Run Migration

Apply the migrations to set up the media storage table:

```
php artisan migrate
```

Uses
----

[](#uses)

To use media storage in any model (e.g., User Blog, Product), add the `HasMedia` trait:

```
use AnisAronno\MediaGallery\Traits\HasMedia;
use HasMedia;
```

### Eloquent Factories Relation Mapping

[](#eloquent-factories-relation-mapping)

For setting up seed data with relation mapping (e.g., User has Blog, Blog uses HasMedia Trait), use the following code in a seeder:

```
use App\Models\User;
use AnisAronno\MediaGallery\Database\Factories\MediaFactory;

User::factory(20)
    ->hasAttached(
        MediaFactory::new()->count(5)
    )
    ->afterCreating(function (User $user)
    {
        $featuredMedia                     = $user->media()->first();
        $featuredMedia->pivot->is_featured = true;
        $featuredMedia->pivot->save();
    })
    ->create();
```

### Retrieve media by owner

[](#retrieve-media-by-owner)

To retrieve media by the user, use the `HasMedia` trait on the User/Team/Admin or any other model authorized to upload media:

```
use AnisAronno\MediaGallery\Traits\HasMedia;

use HasOwnedMedia;

$user = User::find(1); // or auth()->user();
$user->ownedMedia();
```

Absolutely, here's the updated text with subheadings for each section:

### Authentication and Configuration

[](#authentication-and-configuration)

#### Customizing Authentication Guard:

[](#customizing-authentication-guard)

You can customize the authentication guard for the routes by [publishing the config file](#publish-migration-and-config) and changing the 'guard' key to your desired authentication guard.

```
'guard' => ['auth'],
```

Alternatively, you can use the API middleware.

```
'guard' => ['auth:sanctum'],
```

#### Restricting Media Viewing:

[](#restricting-media-viewing)

Set `view_all_media_anyone` to `false` to restrict media viewing to user-uploaded images only; default is `true`, allowing all media viewing.

```
'view_all_media_anyone' => false,
```

#### Defining Gate for Managing Media:

[](#defining-gate-for-managing-media)

Defines `canManageMediaContent` gate in `AuthServiceProvider.php` allowing designated users to manage media content.

```
use Illuminate\Support\Facades\Gate;

Gate::define('canManageMediaContent', function (User $user) {
    return in_array($user->email, [
        'contact@anichur.com',
    ]);
});
```

#### Cache Expiry Time:

[](#cache-expiry-time)

Set Cache Expiry time. Default value is 1440.

```
'cache_expiry_time' => 1440,
```

Use Media with Relational Model
-------------------------------

[](#use-media-with-relational-model)

For storing media for a relational model (e.g., Blog), use the following methods:

- Attach: `$blog->media()->attach(array $id)`
- Sync: `$blog->media()->sync(array $id)`
- Delete: `$blog->media()->detach(array $id)`

Working with Single or Featured Media
-------------------------------------

[](#working-with-single-or-featured-media)

To work with a single or featured media, use the `featuredMedia` method and set `isFeatured` to `true` in the second parameter:

- Attach: `$blog->featuredMedia()->attach(array $id, ['is_featured' => 1])`

Note: Sync and detach are the same; use `featuredMedia` instead of `featuredMedia`.

Helper Methods
--------------

[](#helper-methods)

You can also use helper methods for media management:

- For Attach: `$blog->attachMedia(array $ids, $isFeatured = false)`
- For Sync: `$blog->syncMedia(array $ids, $isFeatured = false)`
- For Delete: `$blog->detachMedia(array $ids, $isFeatured = false)`

API Route for Media/Media
-------------------------

[](#api-route-for-mediamedia)

To manage your media storage, you can use the following routes:

- Get all media: `api/media` (GET)
- Get a single media: `api/media/{id}` (GET)
- Store an media: `api/media` (POST)
- Delete an media: `api/media/{id}` (DELETE)
- Update an media: `api/media/update/{id}` (POST)
- Batch Delete: `media/batch-delete` (POST)

Fetch Media/Media from Relational Model
---------------------------------------

[](#fetch-mediamedia-from-relational-model)

To retrieve media/media from a relational model:

- Fetch all media as an array: `$blog->media`
- Fetch the featured media only: `$blog->media`

You can access media properties like URL, title, mimes, size, and type:

- `$media->url`
- `$media->title`
- `$media->mimes`
- `$media->size`
- `$media->type`

Contribution Guide
------------------

[](#contribution-guide)

Please follow our [Contribution Guide](https://github.com/anisAronno/multipurpose-admin-panel-boilerplate/blob/develop/CONTRIBUTING.md) if you'd like to contribute to this package.

License
-------

[](#license)

This package is open-source software licensed under the [MIT License](https://opensource.org/licenses/MIT).

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

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

Recently: every ~27 days

Total

10

Last Release

755d ago

### Community

Maintainers

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

---

Top Contributors

[![anisAronno](https://avatars.githubusercontent.com/u/38912435?v=4)](https://github.com/anisAronno "anisAronno (18 commits)")

---

Tags

filegalleryimagelaravelmedialaravelwordpressmediagallerywedevs

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[classic-o/nova-media-library

Tool and field that will let you managing files and add them to the posts

154172.0k](/packages/classic-o-nova-media-library)[silvanite/nova-field-cloudinary

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

2772.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)

PHPackages © 2026

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