PHPackages                             khaleejinfotech/laravel-db-sync - 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. [Database &amp; ORM](/categories/database)
4. /
5. khaleejinfotech/laravel-db-sync

ActiveLibrary[Database &amp; ORM](/categories/database)

khaleejinfotech/laravel-db-sync
===============================

Sync remote database to a local database or vice-versa

v1.0.5(3y ago)12121MITPHP

Since Oct 11Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ibilalkhilji/Laravel-Db-Sync)[ Packagist](https://packagist.org/packages/khaleejinfotech/laravel-db-sync)[ RSS](/packages/khaleejinfotech-laravel-db-sync/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

Laravel Db Sync
===============

[](#laravel-db-sync)

[![Laravel DB Sync](https://user-images.githubusercontent.com/14019618/195097554-4c50bff2-26a6-4c06-9a9a-d6639758a0b5.png)](https://user-images.githubusercontent.com/14019618/195097554-4c50bff2-26a6-4c06-9a9a-d6639758a0b5.png)

Introduction
------------

[](#introduction)

Sync remote database to a local database or vice-versa

> **Note** this requires remote MySQL connection to sync the database, and that need to be defined in database.php

Install
-------

[](#install)

Install the package.
*Note: This extension works in Laravel 8 and above.*

```
composer require khaleejinfotech/laravel-db-sync
```

Config
------

[](#config)

You can publish the config file with:

```
php artisan vendor:publish --provider="Khaleejinfotech\LaravelDbSync\LaravelDbSyncServiceProvider" --tag="laravel-db-sync"

```

Database Connections
--------------------

[](#database-connections)

Set the remote database credentials in your `config/database.php` file

```
'connections' => [
    ...

    'mysql_remote' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

    ...
],

```

Observing records
-----------------

[](#observing-records)

To observe changes in records and to sync with remote/local database you must `use Syncable` to your model, by default this package uses its own observer, but you can replace it with your own having the same code of this observer and your custom logics.

You can replace the observer class from the `config/laravel-db-sync.php` file.

```
...
'observer_class' => \Khaleejinfotech\LaravelDbSync\Observers\ModelObserver::class,
...

```

> Note: observer method will only be triggered on eloquent model.

Ignoring models
---------------

[](#ignoring-models)

You can also create a base model with `use Syncable` and can extend your child models, in this case if you ever wanted to ignore a certain model(s) you can ignore them by specifying in the `config/laravel-db-sync.php` file like this:

```
...
'ignore_models' => [
    // Models to be ignored if sync booted in base model.
    User::class,
],
...

```

Defining targets/remote server(s).
----------------------------------

[](#defining-targetsremote-servers)

After setting up connections in the `config/database.php` file you must have to add connection names where the data has to be synced.

```
'targets' => [
    // database connection names
    'mysql_remote',
],

```

> Note: Please specify only remote connections here else it may cause data duplication or may fall into an error.

Handling file uploads of a model
--------------------------------

[](#handling-file-uploads-of-a-model)

If a model handle files then in the configuration file the columns of the model should be defined so that the files can be synced to the local/remote servers.

```
...
    /*\App\Models\Model::class => [
        [
            'column_name' => 'photo',
            'remote_disks' => [
                // remote disks locations from filesystem config file.
                'ftp'
            ],
            'local_disk' => 'public',
            'upload_path_local' => 'folder',
            'upload_path_remote' => 'folder',
        ]
    ],*/
...

```

Events
------

[](#events)

EventDescriptionNoTargetDefinedFired when no remote database defined in config `config/laravel-db-sync.php` file.SyncSuccessFired when each job successfully processed.SyncFailedFired when a job is not processed successfully.SyncUploadSuccessFired when a file upload job successfully processed.SyncUploadFailedFired when a file upload job is not processed successfully.Commands
--------

[](#commands)

CommandDescription`sync:table`Creates migration file.`sync:local`Creates jobs for local database records to be synced on remote.`sync:remote`Creates jobs for remote database records to be synced on local.Usage
-----

[](#usage)

### To sync local database to remote by running:

[](#to-sync-local-database-to-remote-by-running-)

This will create job for each record that need to be synced.

```
php artisan sync:local
```

After that you need run the queue

```
php artisan queue:work
```

### To sync remote database to local by running:

[](#to-sync-remote-database-to-local-by-running-)

This will create job for each record that need to be synced.

```
php artisan sync:remote
```

After that you need run the queue

```
php artisan queue:work
```

> ***Suggestion:*** configure scheduler for above commands to automate synchronization.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

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

Total

6

Last Release

1224d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3294fb4f0b9cf3412c757ef470160f819a62a55a13a6e33409f5f5ee19227f94?d=identicon)[kbinfo4u](/maintainers/kbinfo4u)

---

Top Contributors

[![ibilalkhilji](https://avatars.githubusercontent.com/u/14019618?v=4)](https://github.com/ibilalkhilji "ibilalkhilji (48 commits)")

### Embed Badge

![Health badge](/badges/khaleejinfotech-laravel-db-sync/health.svg)

```
[![Health](https://phpackages.com/badges/khaleejinfotech-laravel-db-sync/health.svg)](https://phpackages.com/packages/khaleejinfotech-laravel-db-sync)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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