PHPackages                             maxkhim/laravel-storage-dedupler - 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. maxkhim/laravel-storage-dedupler

ActiveLibrary

maxkhim/laravel-storage-dedupler
================================

Laravel package for deduplication files in storage and analyze potential disk space savings

1.0.2(5mo ago)47156↓100%MITPHPPHP ^8.2

Since Oct 24Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/maxkhim/laravel-storage-dedupler)[ Packagist](https://packagist.org/packages/maxkhim/laravel-storage-dedupler)[ RSS](/packages/maxkhim-laravel-storage-dedupler/feed)WikiDiscussions master Synced 1mo ago

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

Dedupler - Laravel package prevent's file duplications
======================================================

[](#dedupler---laravel-package-prevents-file-duplications)

[![Latest Version](https://camo.githubusercontent.com/405784c17388655af1dee922817c289dfd875d63e494a76faf5b23a41daf72cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61786b68696d2f6c61726176656c2d73746f726167652d64656475706c65722e7376673f7374796c653d666c6174266c6162656c3d5061636b6167697374266c6f676f3d7061636b6167697374266c6f676f436f6c6f723d666666666666)](https://packagist.org/packages/maxkhim/laravel-storage-dedupler)[![Laravel](https://camo.githubusercontent.com/9a4912d6bb93e540eb534bc44bb4c3987118ad05033492cf56205f845502d37c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302b2d3030376563362e7376673f6c6f676f3d6c61726176656c266c6f676f436f6c6f723d666666666666)](https://laravel.com)[![License](https://camo.githubusercontent.com/ac12e92f09dc2c07327571028a48d8c36510cb00d943a0428429f78856593f2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d61786b68696d2f6c61726176656c2d73746f726167652d64656475706c65722e7376673f636f6c6f723d303037656336266c6162656c3d4c6963656e7365)](https://packagist.org/packages/maxkhim/laravel-storage-dedupler)

### Stop storing duplicate files in your Laravel application.

[](#stop-storing-duplicate-files-in-your-laravel-application)

Tired of seeing the same file stored multiple times? When users upload duplicates, your storage bloats, backups grow, and data consistency suffers.

**Dedupler** is an elegant Laravel package that solves this once and for all. It automatically prevents file duplicates using SHA-1 hashing and provides a beautiful polymorphic API to manage your attachments.

✨ Why Dedupler?
---------------

[](#-why-dedupler)

- 🚫 **Zero Duplicates** - Automatic deduplication using SHA-1 hashing
- 🔗 **Polymorphic Magic** - Attach files to any model with ease
- 💾 **Storage Efficient** - Save significant disk space
- 🎯 **Simple API** - Intuitive methods for attachment management
- ⚡ **Laravel Native** - Seamlessly integrates with Laravel's ecosystem

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require maxkhim/laravel-storage-dedupler
```

#### (Optional) Analyse legacy storage directory

[](#optional-analyse-legacy-storage-directory)

Finds duplicate files by SHA1 hash in directory and subdirectories and calculate potential disk space savings

```
php artisan dedupler:analyse-legacy /absolute/path/to/legacy/storage/directory
```

### 2. Init package

[](#2-init-package)

This command make all necessary migrations, and verifies application configuration (storage, models, etc.) to ensure the package is ready to use

```
php artisan dedupler:install
```

🔧 How to use
------------

[](#-how-to-use)

### 1. Use Facade Dedupler to Store Deduplicated files

[](#1-use-facade-dedupler-to-store-deduplicated-files)

```
/** @var \Illuminate\Http\UploadedFile $file */
/** @var \Maxkhim\Dedupler\Models\UniqueFile $uniqueFile */
$uniqueFile = Dedupler::storeFromUploadedFile($file);
```

```
/** @var string $absolutePathToFile */
/** @var \Maxkhim\Dedupler\Models\UniqueFile $uniqueFile */
$uniqueFile = Dedupler::storeFromPath($absolutePathToFile);
```

```
/** @var string $fileContent */
/** @var \Maxkhim\Dedupler\Models\UniqueFile $uniqueFile */
$uniqueFile = Dedupler::storeFromContent($content, 'direct_content_file.ext');
```

### 2. Add Trait to Your Model to keep deduplicated files attached to models

[](#2-add-trait-to-your-model-to-keep-deduplicated-files-attached-to-models)

```
