PHPackages                             codebuglab/laravel-media-removable - 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. codebuglab/laravel-media-removable

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

codebuglab/laravel-media-removable
==================================

Automatically remove media like images, videos, and audios from storage folder once record with media deleted or updated from database

v0.0.2-beta(4y ago)027MITPHPPHP &gt;=7.0

Since Aug 26Pushed 4y ago1 watchersCompare

[ Source](https://github.com/codebuglab/laravel-media-removable)[ Packagist](https://packagist.org/packages/codebuglab/laravel-media-removable)[ RSS](/packages/codebuglab-laravel-media-removable/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

⚡⚡⚡ Laravel Media Removable
===========================

[](#-laravel-media-removable)

Automatically remove media like images, videos, and audios from storage folder once record with media deleted or updated from database

[![Laravel media removable](logo.png)](logo.png)

Table of contents
-----------------

[](#table-of-contents)

- [Setup](#setup)
    - [Installation](#installation)
    - [Publish](#publish)
- [Instructions](#Instructions)
    - [Using The Model](#using-the-model)
    - [Using Config File](#using-config-file)
    - [Important Notice](#important-notice)
- [Testing](#testing)
- [License](#license)

Setup
-----

[](#setup)

### Installation

[](#installation)

To install this package through composer run the following command in the terminal

```
composer require codebuglab/laravel-media-removable
```

### Publish

[](#publish)

You have to publish config file with this artisan command:

```
php artisan vendor:publish --provider="CodeBugLab\MediaRemovable\MediaRemovableServiceProvider"
```

- File `media-removable.php` will be publish in `config` folder after that.
- run `php artisan config:clear` to update application with published file.

Instructions
------------

[](#instructions)

Here is multiple ways to use this package to delete media files from your project during updating and deleting database row using eloquent.

- You have to use the trait `CodeBugLab\MediaRemovable\MediaRemovable`

### Using The Model

[](#using-the-model)

- To use model method all you have to do is to add a private static parameter `mediaField`
- if you don't add `mediaField` automatically the package will throw and exception.

```
use CodeBugLab\MediaRemovable\MediaRemovable;

class MyModel extends Eloquent
{
    use MediaRemovable;

    private static $mediaFields = ['image']; //image is column_name you want to delete

}
```

- by using the method the package will determine files path from config file which already set at `config\media_removable.php`
- if you want to change file path for all the project you can change it from config file or use the private method `mediaPath` like this

```
use CodeBugLab\MediaRemovable\MediaRemovable;

class MyModel extends Eloquent
{
   use MediaRemovable;

   private static $mediaFields = ['image']; //image is column_name you want to delete

   private static $mediaPath = "storage/app/public/"; //The path of you media files
}
```

- If you have a complex structure to your media files in your application you can use the private method `mediaDetails` instead

```
use CodeBugLab\MediaRemovable\MediaRemovable;

class MyModel extends Eloquent
{
   use MediaRemovable;

   // set all columns and paths for this model
   public static $mediaDetails = [
       [
           'field' => 'image',
           'path' => 'storage/app/public/images/'
       ],
       [
           'field' => 'profile_picture',
           'path' => 'storage/app/public/profile/'
       ],
   ];
}
```

- Here you can determine every column folder path individually.

### Using Config File

[](#using-config-file)

- Alternatively you can use the config file to set all your media details instead of the model.
- keep using `MediaRemovable` trait.

```
use CodeBugLab\MediaRemovable\MediaRemovable;

class MyModel extends Eloquent
{
    use MediaRemovable;
}
```

- And then set change your config file as you want

```
return [
    'path' => 'storage/app/public/',

    'fields' => ['image']
];
```

- The above code expect field `image` in all models used `MediaRemovable` trait, We don't think it's a practical way but we keep it if someone need it.
- If you have more details than that you can use `details` instead.

```
return [
    'details' => [
        'table_name' => [
            [
                'field' => 'field_name',
                'path' => 'storage/app/public/directory/'
            ],
            [
                'field' => 'another_field_name',
                'path' => 'storage/app/public/another_directory/'
            ]
        ],
        'another_table_name' => [
            [
                'field' => 'image',
                'path' => 'storage/app/public/'
            ]
        ]
    ]
];
```

- Inside `details` array we use table name to track model details.
- You can set multiple `tables` and `fields` as you can see, this way will make the model much cleaner specially if you have multiple fields.

### Important Notice

[](#important-notice)

- The priority in this package is for `config` file information so if you set information to your `config` and your `model`, the `model` information will be overwrite by `config` information so be carful with that.

Testing
-------

[](#testing)

To run test use this command `vendor/bin/phpunit`

License
-------

[](#license)

This package is a free software distributed under the terms of the MIT license.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 90.9% 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 ~153 days

Total

2

Last Release

1572d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1b739843a13277460d1b33db36cacdd3fe8c5c5942f458ed26284aba28c16849?d=identicon)[CodeBugLab](/maintainers/CodeBugLab)

---

Top Contributors

[![moelkomy](https://avatars.githubusercontent.com/u/70802292?v=4)](https://github.com/moelkomy "moelkomy (10 commits)")[![MahmoudBelalNasr](https://avatars.githubusercontent.com/u/74736585?v=4)](https://github.com/MahmoudBelalNasr "MahmoudBelalNasr (1 commits)")

---

Tags

phplaravellaravel-packagelaravel-storageeloquent-modelslaravel-trait

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[madnest/madzipper

Easier zip file handling for Laravel applications.

1382.3M6](/packages/madnest-madzipper)[sopamo/laravel-filepond

Laravel backend module for filepond uploads

215272.2k3](/packages/sopamo-laravel-filepond)[soarecostin/file-vault

192195.0k](/packages/soarecostin-file-vault)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)

PHPackages © 2026

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