Laravel Storage Dedupler

Laravel Storage Dedupler stats

Downloads
10
Stars
1
Open Issues
0
Forks
0

View on GitHub →

Module for Laravel 10+ for deduplication of files in storage

Dedupler

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?

  • 🚫 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

1. Install via Composer

composer require maxkhim/laravel-storage-dedupler

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

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

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Model;
use Maxkhim\Dedupler\Traits\Deduplable;
 
class Post extends Model
{
use Deduplable;
}
 
$post = new Post([...]);
/** @var \Illuminate\Http\UploadedFile $file */
/** @var \Maxkhim\Dedupler\Models\UniqueFile $uniqueFile */
$uniqueFile = $post->storeUploadedFile($file);
/** @var \Maxkhim\Dedupler\Models\UniqueFile $uniqueFile */
$uniqueFile = $post->storeLocalFile($absolutePathToFile);
/** @var \Maxkhim\Dedupler\Models\UniqueFile $uniqueFile */
$uniqueFile = $post->storeContentFile($content, 'direct_content_file.ext');

3. Detach unique files from models

$post->detachUniqueFile($sha1_hash)

About Deduplication

When you upload the same file multiple times:

// First upload - file is stored
$file1 = $post->storeUploadedFile($sameFile);
OR
$file1 = Dedupler::storeFromUploadedFile($sameFile);
// Second upload - returns existing UniqueFile, no duplicate created
$file2 = $post->storeUploadedFile($sameFile);
OR
$file1 = Dedupler::storeFromUploadedFile($sameFile);
 
$file1->id === $file2->id; // true - same database record and same file in storage

🛣️ API Reference

Enable RESTapi endpoint to check file existence

DEDUPLER_REST_ENABLED=true
GET http://localhost:8080/api/dedupler/v1/files/da39a3ee5e6b4b0d3255bfef95601890afd80709
{
"success": true,
"data": {
"hash": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"sha1_hash": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"md5_hash": "d41d8cd98f00b204e9800998ecf8427e",
"exists": false,
"filename": "da39a3ee5e6b4b0d3255bfef95601890afd80709.pdf",
"path": "da\/39\/da39a3ee5e6b4b0d3255bfef95601890afd80709.pdf",
"mime_type": "application\/pdf",
"size": 102400,
"size_human": "100 KB",
"disk": "deduplicated",
"status": "completed",
"created_at": "2025-10-22T18:40:41.000000Z",
"updated_at": "2025-10-22T18:40:41.000000Z",
"links_count": 94
}
}

License

The MIT License (MIT).

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Maxkhim Laravel Storage Dedupler Related Articles

Laravel Database Operations image

Laravel Database Operations

Read article
Laravel.io Podcast Episode 13 image

Laravel.io Podcast Episode 13

Read article
Laravel Tricks is now open sourced image

Laravel Tricks is now open sourced

Read article
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit