PHPackages                             masterro/laravel-file-cleaner - 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. masterro/laravel-file-cleaner

ActiveLibrary

masterro/laravel-file-cleaner
=============================

Laravel console command for deleting temp files and associated model instances.

1.7.0(5y ago)197.1kMITPHPPHP &gt;=5.5.9

Since Apr 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/MasterRO94/laravel-file-cleaner)[ Packagist](https://packagist.org/packages/masterro/laravel-file-cleaner)[ RSS](/packages/masterro-laravel-file-cleaner/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (7)Versions (21)Used By (0)

 [![](https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg)](https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg)

 [ ![Latest Stable Version](https://camo.githubusercontent.com/e30883eda0098cad79d31c9da6a2674b790cbc374453831cc5df113fe23688db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6173746572726f2f6c61726176656c2d66696c652d636c65616e65722e7376673f7374796c653d666c61742d726f756e646564) ](https://packagist.org/packages/masterro/laravel-file-cleaner) [ ![Total Downloads](https://camo.githubusercontent.com/2d03f5c05d1be1f481f3c22a36d6708609233e7594a1e8415c074bd48f548e31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6173746572726f2f6c61726176656c2d66696c652d636c65616e65722e7376673f7374796c653d666c61742d726f756e646564) ](https://packagist.org/packages/masterro/laravel-file-cleaner) [ ![Build Status](https://github.com/MasterRO94/laravel-file-cleaner/workflows/Tests/badge.svg) ](https://github.com/MasterRO94/laravel-file-cleaner/actions) [ ![License](https://camo.githubusercontent.com/077aaf4a8fa1d688c63886f30c3c1d3181aa1d194e2d04538c994b7fb713be42/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d6173746572524f39342f6c61726176656c2d66696c652d636c65616e6572) ](https://github.com/MasterRO94/laravel-file-cleaner/blob/master/LICENSE.txt)

 [ ![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg) ](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)

File Cleaner for Laravel
========================

[](#file-cleaner-for-laravel)

File Cleaner is a package for Laravel 5+ that provides deleting files and associated model instances.

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

[](#installation)

### Step 1: Composer

[](#step-1-composer)

From the command line, run:

```
composer require masterro/laravel-file-cleaner

```

### Step 2: Service Provider (For Laravel &lt; 5.5)

[](#step-2-service-provider-for-laravel--55)

For your Laravel app, open `config/app.php` and, within the `providers` array, append:

```
MasterRO\LaravelFileCleaner\FileCleanerServiceProvider::class

```

This will bootstrap the package into Laravel.

### Step 3: Publish Configs

[](#step-3-publish-configs)

First from the command line, run:

```
php artisan vendor:publish --provider="MasterRO\LaravelFileCleaner\FileCleanerServiceProvider"

```

After that you will see `file-cleaner.php` file in config directory

For this package you may set such configurations:

- `paths` - Paths where temp files are storing (or will be storing), relative to root directory
- `excluded_paths` - Excluded directory paths where nothing would be deleted, relative to root directory
- `excluded_files` - Excluded files path that would not be deleted, relative to root directory
- `time_before_remove` - Time after which the files will be deleted | *default **60** minutes*
- `model` - Model which instances will be deleted with associated files | *optional*
- `file_field_name` - Field name that contains the name of the removing file | *optional, **only if model set***
- `remove_directories` - Remove directories flag, if set to true all nested directories would be removed | *default **true***
- `relation` - Relation, remove files and model instances only if model instance does not have a set relation

### Voter callback

[](#voter-callback)

Additionally, you can set a static voter callback or invokable object to have more power on controlling deletion logic.
You can register it in one of yours Service providers. The callback will be called after `time_before_remove` and `excluded_*` checks.

```
FileCleaner::voteDeleteUsing(function($path, $entity) {
    if (isset($entity) && !$entity->user->isActive()) {
        return true;
    }

    return false;
});
```

If callback return `true` file and optionally associated record in db will be removed.
If callback return `false` file and record won't be removed.
Otherwise `relation` check will be performed.

Usage
-----

[](#usage)

### Scheduling

[](#scheduling)

Add new command call to schedule function:

> Have a look at [Laravel's task scheduling documentation](https://laravel.com/docs/scheduling), if you need any help.

```
protected function schedule(Schedule $schedule)
{
    $schedule->command('file-cleaner:clean')->everyMinute();
}
```

And that's all. If your cron set up everything will work.

### Manual, using artisan console

[](#manual-using-artisan-console)

You can run deleting manually, just run from the command line:

```
php artisan file-cleaner:clean

```

And see the output.

Or if you want to delete files without checking time (just delete all files from all set directories) use the --force flag (or -f shortcut):

```
php artisan file-cleaner:clean -f

```

You can even override config directories `paths`, `excluded_paths` and `excluded_files` values with `--directories`, `--excluded-paths` and `--excluded-files` options (separate by comma):

```
php artisan file-cleaner:clean -f --directories=storage/temp/images,public/uploads/test

```

```
php artisan file-cleaner:clean -f --excluded-paths=public/uploads/images/default,public/uploads/test

```

```
php artisan file-cleaner:clean -f --excluded-files=public/uploads/images/default.png,public/uploads/test/01.png

```

Also you can even override `remove_directories` config value with `--remove-directories` option:

```
php artisan file-cleaner:clean -f --directories=storage/temp/images,public/uploads/test --remove-directories=false

```

#### *I will be grateful if you star this project :)*

[](#i-will-be-grateful-if-you-star-this-project-)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Recently: every ~182 days

Total

20

Last Release

2056d ago

PHP version history (2 changes)1.2.0PHP &gt;=5.4.0

1.3.3PHP &gt;=5.5.9

### Community

Maintainers

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

---

Top Contributors

[![MasterRO94](https://avatars.githubusercontent.com/u/7365389?v=4)](https://github.com/MasterRO94 "MasterRO94 (72 commits)")

---

Tags

laravelfilescleandelete

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/masterro-laravel-file-cleaner/health.svg)

```
[![Health](https://phpackages.com/badges/masterro-laravel-file-cleaner/health.svg)](https://phpackages.com/packages/masterro-laravel-file-cleaner)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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