PHPackages                             oguzhankrcb/datamigrator - 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. oguzhankrcb/datamigrator

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

oguzhankrcb/datamigrator
========================

A simple package for data migration

1.0.1(3y ago)30101[2 PRs](https://github.com/oguzhankrcb/DataMigrator/pulls)MITPHPPHP ^8.0|^8.1|^8.2

Since Feb 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/oguzhankrcb/DataMigrator)[ Packagist](https://packagist.org/packages/oguzhankrcb/datamigrator)[ Docs](https://github.com/oguzhankrcb/datamigrator)[ RSS](/packages/oguzhankrcb-datamigrator/feed)WikiDiscussions main Synced 1mo ago

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

[![](https://user-images.githubusercontent.com/7572058/221666178-3157c1b8-fd83-48e8-956c-ec63dbcbead5.jpeg)](https://user-images.githubusercontent.com/7572058/221666178-3157c1b8-fd83-48e8-956c-ec63dbcbead5.jpeg)

Data Migrator
=============

[](#data-migrator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ed119bfac044d53b63f7b1fbb0859a7cb309c88c6009198ea29976db190f766e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f67757a68616e6b7263622f646174616d69677261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oguzhankrcb/datamigrator)[![GitHub Tests Action Status](https://camo.githubusercontent.com/eba91fca327deb9c95cfc683cd79831a03598ce5274a3e104e3c878d0163b60f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f67757a68616e6b7263622f646174616d69677261746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/oguzhankrcb/datamigrator/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/261cea5cddc8b110ce5b631acc9adbd97ea3f50c6b0d418e5d7f01116da798ca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f67757a68616e6b7263622f646174616d69677261746f722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/oguzhankrcb/datamigrator/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/3210889a9d74d329a8e6c3c859de1518cbb6a4a77ca62ab0b75cc213adf07ba3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f67757a68616e6b7263622f646174616d69677261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/oguzhankrcb/datamigrator)

Data Migrator is a PHP/Laravel package that helps you migrate data from one model to another, even if they have different structures. It's especially useful when you're migrating data between models with different database schemas.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require oguzhankrcb/datamigrator
```

Usage
-----

[](#usage)

### Transforming Data

[](#transforming-data)

To transform data from one model to another, use the `transformData` method. This method takes two arrays: `$toModelPrototype` and `$fromModel`.

`$toModelPrototype` should be an array that describes the structure of the new model, with the keys being the names of the new fields, and the values being the names of the fields from the old model that the new fields should be based on. For example:

```
$toModelPrototype = [
    'id'         => '[id]',
    'unique_id'  => '[unique_number.id]',
    'name'       => '[data->name]',
    'categories' => [
        'first_category'  => '[data->categories->category_2]',
        'second_category' => '[data->categories->category_3]',
    ],
    'alias_with_item_code' => '[data->alias][data->item->code]',
    'alias'                => '[data->alias]',
    'item_code'            => '[data->item->code]',
    'status'               => '[data->status]',
];
```

`$fromModel` should be an array that represents a single row of data from the old model, with the keys being the names of the fields from the old model, and the values being the actual values. For example:

```
$fromModel = [
    'id'            => 1,
    'unique_number' => 'lxAxmUlkfc',
    'data'          => [
        'name'       => 'John Doe',
        'alias'      => 'JD',
        'categories' => [
            'category_1' => 'Bronze',
            'category_2' => 'Silver',
            'category_3' => 'Gold',
        ],
        'item' => [
            'code' => 196854,
        ],
        'status' => true,
    ],
];
```

Here's an example of how to use `transformData`:

```
use Oguzhankrcb\DataMigrator\Facades\DataMigrator;

$newData = DataMigrator::transformData($toModelPrototype, $fromModel);
```

The `$newData` array will contain the transformed data, with the keys being the names of the new fields, and the values being the corresponding values from the old model.

Output Example:

```
[
    'id'         => 1,
    'unique_id'  => 'lxAxmUlkfc1',
    'name'       => 'John Doe',
    'categories' => [
        'first_category'  => 'Silver',
        'second_category' => 'Gold',
    ],
    'alias_with_item_code' => 'JD196854',
    'alias'                => 'JD',
    'item_code'            => '196854',
    'status'               => true,
]
```

### Transferring Data

[](#transferring-data)

To transfer all data from one model to another, use the `transferAllDataFromModelToModel` method. This method takes three arguments: `$transferToModel`, `$toModelPrototype`, and `$transferFromModel`.

`$transferToModel` should be the fully qualified class name of the model you want to transfer the data to. For example:

```
$transferToModel = \App\Models\User::class;
```

`$toModelPrototype` should be the same array you used with `transformData`.

`$transferFromModel` should be the fully qualified class name of the model you want to transfer the data from. For example:

```
$transferFromModel = \App\Models\LegacyUser::class;
```

Here's an example of how to use `transferAllDataFromModelToModel`:

```
use App\Models\Order;
use App\Models\Invoice;
use Oguzhankrcb\DataMigrator\Facades\DataMigrator;

// Define the fields to transfer from Order to Invoice
$toModelPrototype = [
    'invoice_number' => '[order_number]',
    'customer_name' => '[customer->name]',
    'customer_email' => '[customer->email]',
    'total_amount' => '[amount]',
    'total_amount_with_currency' => '[amount]€',
];

// Transfer the data from Order to Invoice
DataMigrator::transferAllDataFromModelToModel(Invoice::class, $toModelPrototype, Order::class);
```

In this example, we define the fields we want to transfer from the `Order` model to the `Invoice` model using the `$toModelPrototype` array. Then we call the `transferAllDataFromModelToModel` method, passing in the `Invoice` and `Order` models and the `$toModelPrototype` array.

This method will transfer all the data from the `Order` model to the `Invoice` model, creating a new `Invoice` model for each `Order` model in the database.

If you want to transfer only one model data to another model you can use `transferDataModelToModel` method only difference from the `transferAllDataFromModelToModel` method is this method only transfers one model not all models.

Here's an example of how to use `transferDataModelToModel`:

```
use App\Models\Order;
use App\Models\Invoice;
use Oguzhankrcb\DataMigrator\Facades\DataMigrator;

// Define the fields to transfer from Order to Invoice
$toModelPrototype = [
    'invoice_number' => '[order_number]',
    'customer_name' => '[customer->name]',
    'customer_email' => '[customer->email]',
    'total_amount' => '[amount]',
    'total_amount_with_currency' => '[amount]€',
];

$orderInstance = Order::find(1);

// Transfer the data from Order to Invoice
$transferedModel = DataMigrator::transferDataModelToModel(Invoice::class, $toModelPrototype, $orderInstance);
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Contributions are welcome! If you find any bugs or issues, please [open a new issue](https://github.com/oguzhankrcb/DataMigrator/issues/new) or submit a pull request.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Oğuzhan KARACABAY](https://github.com/oguzhankrcb)
- [All Contributors](../../contributors)

License
-------

[](#license)

The DataMigrator package is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

2

Last Release

1165d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9517bc58310e283693396c5ed6a1c7c5bbc7aa1121e62012a1abe1dd2ecf64db?d=identicon)[oguzhankrcb](/maintainers/oguzhankrcb)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (5 commits)")[![oguzhankrcb](https://avatars.githubusercontent.com/u/7572058?v=4)](https://github.com/oguzhankrcb "oguzhankrcb (3 commits)")

---

Tags

laraveloguzhankrcbdatamigrator

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/oguzhankrcb-datamigrator/health.svg)

```
[![Health](https://phpackages.com/badges/oguzhankrcb-datamigrator/health.svg)](https://phpackages.com/packages/oguzhankrcb-datamigrator)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[watson/validating

Eloquent model validating trait.

9723.3M46](/packages/watson-validating)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[outerweb/settings

Application wide settings stored in your database

4899.2k5](/packages/outerweb-settings)

PHPackages © 2026

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