定制 mrbohem/larasync 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mrbohem/larasync

Composer 安装命令:

composer require mrbohem/larasync

包简介

Laravel Database Sync with UI dashboard

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Larasync is a Laravel package that lets you compare and sync data between two databases through a beautiful Livewire-powered web dashboard. Connect any combination of SQLite, MySQL, or PostgreSQL databases, see a side-by-side row-count comparison for every table, and sync individual tables or all tables at once — right from your browser.

✨ Features

  • 🔌 Connect any two databases — SQLite, MySQL, or PostgreSQL
  • 📊 Side-by-side table comparison — row counts, diff, and sync status at a glance
  • 🔄 One-click sync — sync a single table or all tables sequentially
  • ↔️ Bi-directional sync — choose DB1 → DB2 or DB2 → DB1
  • 🏷️ Auto-labeling — databases are auto-detected as Local or Cloud
  • 🚫 Ignored tables — exclude tables (e.g. sessions, telescope_*) from comparison & sync
  • 🖥️ Beautiful Livewire dashboard — real-time progress, logs, and status indicators
  • ⚙️ Zero config needed — works out of the box with .env variables

📋 Requirements

  • PHP ≥ 8.3
  • Laravel 11.x or 12.x
  • Livewire 3.6+

🚀 Installation

1. Install the package via Composer

composer require mrbohem/larasync --dev

2. (Optional) Publish the config file

php artisan vendor:publish --tag="larasync-config"

This creates config/larasync.php where you configure your two database connections and ignored tables.

3. (Optional) Publish the views

If you want to customize the dashboard UI:

php artisan vendor:publish --tag="larasync-views"

⚙️ Configuration

After publishing, open config/larasync.php and configure your two databases. You can set values directly or use .env variables:

Config File

return [
    'db1' => [
        'driver'   => env('LARASYNC_DB1_DRIVER', 'sqlite'),
        'host'     => env('LARASYNC_DB1_HOST'),
        'port'     => env('LARASYNC_DB1_PORT', '3306'),
        'database' => env('LARASYNC_DB1_DATABASE'),
        'username' => env('LARASYNC_DB1_USERNAME'),
        'password' => env('LARASYNC_DB1_PASSWORD', ''),
    ],

    'db2' => [
        'driver'   => env('LARASYNC_DB2_DRIVER', 'mysql'),
        'host'     => env('LARASYNC_DB2_HOST'),
        'port'     => env('LARASYNC_DB2_PORT', '3306'),
        'database' => env('LARASYNC_DB2_DATABASE'),
        'username' => env('LARASYNC_DB2_USERNAME'),
        'password' => env('LARASYNC_DB2_PASSWORD', ''),
    ],

    'ignored_tables' => [
        'sessions',
        'telescope_entries_tags',
        'telescope_entries',
        'telescope_monitoring',
        'pulse_entries',
        'pulse_values',
        'pulse_aggregates',
    ],
];

.env Example

# ── Database 1 (e.g. local SQLite) ──
LARASYNC_DB1_DRIVER=sqlite
LARASYNC_DB1_DATABASE=database.sqlite

# ── Database 2 (e.g. remote MySQL) ──
LARASYNC_DB2_DRIVER=mysql
LARASYNC_DB2_HOST=your-cloud-db-host.com
LARASYNC_DB2_PORT=3306
LARASYNC_DB2_DATABASE=your_database
LARASYNC_DB2_USERNAME=your_username
LARASYNC_DB2_PASSWORD=your_password

Note: For SQLite, the database value is resolved relative to Laravel's database_path() (i.e. the database/ directory).

🖥️ Usage

Access the Dashboard

Once installed, visit the sync dashboard in your browser:

https://your-app.test/sync-db

The route is automatically registered by the package at /sync-db.

Dashboard Workflow

  1. Configure connections — Enter or verify the credentials for DB1 and DB2 (pre-filled from config)
  2. Test connections — Click the test button for each database to verify connectivity
  3. Compare — Hit "Compare" to see a table-by-table row-count comparison
  4. Choose sync direction — Select DB1 → DB2 or DB2 → DB1
  5. Sync — Sync individual tables with one click, or use "Sync All" to sync every table sequentially

Supported Drivers

Driver Value Notes
SQLite sqlite Always treated as Local
MySQL mysql Local or Cloud auto-detected
PostgreSQL pgsql Local or Cloud auto-detected

Ignoring Tables

Add table names to the ignored_tables array in config/larasync.php to exclude them from comparison and sync:

'ignored_tables' => [
    'sessions',
    'telescope_entries',
    'jobs',
    'failed_jobs',
    // add your tables here...
],

⚠️ Important Notes

  • Sync is destructive — Syncing a table will truncate the target table and replace all its data with the source table's data. Always back up your databases before syncing.
  • Foreign key constraints are temporarily disabled during sync to avoid constraint violations.
  • Large tables are synced in chunks of 500 rows for efficiency.
  • The dashboard route (/sync-db) uses the web middleware by default. You may want to add authentication middleware in production — see Protecting the Dashboard.

🔒 Protecting the Dashboard

The /sync-db route uses only the web middleware by default. In production, you should protect it with authentication. You can do this by adding middleware in your app's route service provider or by overriding the package route:

// In routes/web.php
use MrBohem\Larasync\Http\Livewire\SyncDashboard;

Route::get('sync-db', SyncDashboard::class)
    ->middleware(['web', 'auth', 'admin'])  // add your middleware
    ->name('larasync.dashboard');

🧪 Testing

composer test

👤 Credits

📄 License

The MIT License (MIT). Please see License File for more information.

mrbohem/larasync 适用场景与选型建议

mrbohem/larasync 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「mrbohem」 「larasync」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mrbohem/larasync 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mrbohem/larasync 我们能提供哪些服务?
定制开发 / 二次开发

基于 mrbohem/larasync 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-13