PHPackages                             taylornetwork/backup-importer - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. taylornetwork/backup-importer

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

taylornetwork/backup-importer
=============================

v0.1(8y ago)018MITPHPPHP &gt;=7.1.0

Since Mar 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/taylornetwork/backup-importer)[ Packagist](https://packagist.org/packages/taylornetwork/backup-importer)[ RSS](/packages/taylornetwork-backup-importer/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Backup Importer
===============

[](#backup-importer)

This package will allow you to import data to your database from a backup database that is not identical.

This is useful if you re-write an application and the database structure changes.

Install
-------

[](#install)

Using Composer

```
$ composer require taylornetwork/backup-importer
```

### Publish Config

[](#publish-config)

```
$ php artisan vendor:publish
```

### Add Backup Database Config

[](#add-backup-database-config)

By default this will use your `mysql` database connection with the `DB_BACKUP_DATABASE` value from your `.env` file or `backup` as the database name

Add connection details to `config/backup-importer.php`

Usage
-----

[](#usage)

### Run your importers

[](#run-your-importers)

```
$ php artisan importer:run
```

### Create an Importer

[](#create-an-importer)

```
$ php artisan importer:new CustomerImporter
```

Would generate an importer `App\Backup\Importers\CustomerImporter.php` by default.

### Simple Importer

[](#simple-importer)

```
use TaylorNetwork\BackupImporter\BaseImporter;

class CustomerImporter extends BaseImporter
{
    public function import(): int
    {
        return $this->simpleImport();
    }
}
```

By default the importer assumes the following

- There is a model to import to
- The model being imported is `App\Customer` (see Advanced Config to change)
- The backup table name is `customers`
- The backup table fields are all the same as the model's fields

### Advanced Importers

[](#advanced-importers)

You can override the above assumptions on an importer by importer basis

#### Override Model

[](#override-model)

Add a protected `$model` variable in your importer

```
protected $model = App\Models\Customer::class;
```

#### Override the Backup Table Name

[](#override-the-backup-table-name)

Add a protected `$backupTableName` variable in your importer

```
protected $backupTableName = 'xyz_customers';
```

#### Ignore Model (For a Pivot Table)

[](#ignore-model-for-a-pivot-table)

If you don't have a model for this importer set a protected `$ignoreModel` to `true`

```
protected $ignoreModel = true;
```

#### Override Columns From Backup Table

[](#override-columns-from-backup-table)

You can override the columns that are taken from the backup table, or rename them.

Add a public `getColumnMap()` function that returns the array of columns to get.

```
public function getColumnMap(): array
{
    return [
        'firstname as first_name,
        'lastname as last_name',
        'address',
    ];
}
```

#### Example

[](#example)

```
use TaylorNetwork\BackupImporter\BaseImporter;

class CustomerImporter extends BaseImporter
{
    /**
     * Set the model to import to
     */
    protected $model = App\Models\Customer::class;

    /**
     * Set the backup table name
     */
    protected $backupTableName = 'xyz_customers';

    /**
     * Set the columns to get from the backup table
     */
    public function getColumnMap(): array
    {
        return [
            'firstname as first_name',
            'lastname as last_name',
            'address',
        ];
    }

    public function import(): int
    {
       return $this->simpleImport();
    }
}
```

### Customizing the `import()` function

[](#customizing-the-import-function)

The `import()` function by default will return `$this->simpleImport()` which is fine for simple tables with no relations, however you will likely want to customize the import logic.

#### Notes

[](#notes)

- Access the model by `$this->getModel()`
- Access the database query data by `$this->items()`
- Access the fluent builder for more complex queries by `$this->builder()`
- Access the fluent builder AFTER the select call by `$this->select()`
- Whenever you import a row you should call `$this->increment()` to add to the total of rows imported
- If you use `$this->increment()` your return statement should be `$this->getImportTotal()`

#### Example

[](#example-1)

Let's say you have an application that has customers and services. Each customer can have many services with properties. You have the following models which you store in `app/`

- `App\Customer`
- `App\Service`
- `App\CustomerService`

For the customer and service models, you used the simple import method.

```
// App\Backup\Importers\CustomerServiceImporter.php

use TaylorNetwork\BackupImporter\BaseImporter;
use App\Customer;

class CustomerServiceImporter extends BaseImporter
{
    public function getColumnMap(): array
    {
        return [
            'customer_id',
            'service_id',
            'qty',
            'description',
            'last_service_date',
        ];
    }

    public function import(): int
    {
        $rows = $this->select()->where('last_service_date', '!=', null)->get();

        foreach($rows as $row) {
            Customer::find($row->customer_id)->services()->create([
                'service_id' => $row->service_id,
                'qty' => $row->qty,
                'desc' => $row->description,
                'last_date' => $row->last_service_date,
            ]);

            $this->increment();
        }

        return $this->getImportTotal();
    }
}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

2968d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83340094473f0bf5b2cf062bf394df221a52a30aa0e21cd0a77302977d6393ce?d=identicon)[samueljtaylor](/maintainers/samueljtaylor)

---

Top Contributors

[![samyrataylor](https://avatars.githubusercontent.com/u/15961687?v=4)](https://github.com/samyrataylor "samyrataylor (13 commits)")

### Embed Badge

![Health badge](/badges/taylornetwork-backup-importer/health.svg)

```
[![Health](https://phpackages.com/badges/taylornetwork-backup-importer/health.svg)](https://phpackages.com/packages/taylornetwork-backup-importer)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M158](/packages/orchestra-canvas)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)[zonneplan/laravel-module-loader

Module loader for Laravel

24118.4k](/packages/zonneplan-laravel-module-loader)

PHPackages © 2026

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