laravelldone/db-cleaner
Composer 安装命令:
composer require laravelldone/db-cleaner
包简介
Scan database tables for data quality issues (duplicates, typos, whitespace, casing) with a Livewire dashboard and REST API
README 文档
README
A Laravel package that scans your database tables for data quality issues and helps you fix them.
The Problem
Real-world databases accumulate noise over time:
"john doe","John Doe","JOHN DOE"— same person, three records" Engineering ","engineering"— same department, inconsistent casing"Managment","Management"— typo that slipped past validation" alice@example.com"— leading space breaking lookups
These issues corrupt reports, break deduplication logic, and make search unreliable. DB Cleaner detects and fixes them without guesswork.
What It Does
| Issue | How Detected |
|---|---|
| Exact duplicates | GROUP BY col HAVING COUNT(*) > 1 |
| Fuzzy duplicates | Levenshtein distance (configurable threshold) |
| Soundex matches | soundex() grouping |
| Leading/trailing whitespace | col != TRIM(col) |
| Double spaces / tabs | SQL LIKE patterns |
| Casing inconsistencies | GROUP BY LOWER(col) HAVING COUNT(DISTINCT col) > 1 |
| Typos | similar_text() against high-frequency values |
Each column gets a quality score (0–100) and a letter grade (A–F). Scores are stored so you can track improvement over time.
Installation
composer require laravelldone/db-cleaner
php artisan vendor:publish --provider="Laravelldone\DbCleaner\DbCleanerServiceProvider"
php artisan migrate
Quick Start
# Scan all tables and see what's wrong php artisan db-cleaner:scan # Preview what cleaning would do — no data is touched php artisan db-cleaner:clean users --column=name --type=whitespace --dry-run # Apply the fix php artisan db-cleaner:clean users --column=name --type=whitespace
Configuration
config/db-cleaner.php — the key options:
// Limit to specific tables and columns (empty = scan everything) 'tables' => [ 'users' => ['name', 'email'], 'products', ], // Tables never scanned 'exclude_tables' => ['migrations', 'jobs', 'sessions'], // Fuzzy duplicate sensitivity (lower = stricter) 'duplicates' => ['fuzzy_threshold' => 2], // Typo detection similarity (0–100, higher = stricter) 'typos' => ['similarity_threshold' => 85],
CLI
# Scan one table, specific columns php artisan db-cleaner:scan --table=users --columns=name,email # View scan history php artisan db-cleaner:report --table=users --format=json # Clean types: whitespace | casing | duplicate php artisan db-cleaner:clean users --column=name --type=casing --dry-run php artisan db-cleaner:clean users --column=name --type=casing --force
PHP / Facade
use Laravelldone\DbCleaner\Facades\DbCleaner; $analysis = DbCleaner::scan('users'); $analysis->qualityScore; // 73.4 $analysis->grade; // C $analysis->totalIssueCount(); // 28 // Preview before touching anything $actions = DbCleaner::previewClean('users', 'name', 'whitespace'); // Apply (confirm required — no accidental changes) DbCleaner::clean('users', 'name', 'whitespace', confirm: true);
REST API
GET /api/db-cleaner/status — overall DB health
GET /api/db-cleaner/tables — all tables with scores
GET /api/db-cleaner/tables/{table} — detailed column breakdown
POST /api/db-cleaner/tables/{table}/scan — trigger a scan
GET /api/db-cleaner/history — score trends over time
POST /api/db-cleaner/clean/preview — preview cleaning actions
POST /api/db-cleaner/clean/apply — apply (requires "confirm": true)
Protect the API with a token in .env:
DB_CLEANER_API_TOKEN=your-secret
Dashboard
Visit /db-cleaner for a Livewire dashboard with:
- Quality scores and grades per table
- Issue breakdown chart (Chart.js, no npm required)
- Score trend over time
- Run scans and apply cleaning from the browser
Safety
- No data is ever modified without explicit confirmation —
--dry-runin CLI,"confirm": truein the API,confirm: truein PHP - All cleaning runs inside a
DB::transaction() - Fuzzy analysis is skipped on tables over 5,000 rows by default (
max_rows_for_fuzzy) to prevent memory issues
Requirements
- PHP 8.2+
- Laravel 11 or 12
- Livewire 3 or 4
License
MIT
laravelldone/db-cleaner 适用场景与选型建议
laravelldone/db-cleaner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「laravel」 「cleaner」 「duplicates」 「livewire」 「data-quality」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laravelldone/db-cleaner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravelldone/db-cleaner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laravelldone/db-cleaner 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Removes invalid UTF-8 characters from the given text
Cleans files by removing any metadata with the help of mat2, exiftool and qpdf according to BSI guidelines.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-19