PHPackages                             faulker/eloquent-export - 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. faulker/eloquent-export

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

faulker/eloquent-export
=======================

A CLI tool for exporting and importing database data using Laravel's Eloquent models

v0.1.2(9y ago)311.7k2MITPHP

Since Feb 1Pushed 8y ago1 watchersCompare

[ Source](https://github.com/faulker/eloquent-export)[ Packagist](https://packagist.org/packages/faulker/eloquent-export)[ Docs](https://github.com/faulker/eloquent-export)[ RSS](/packages/faulker-eloquent-export/feed)WikiDiscussions master Synced 2mo ago

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

Laravel Eloquent Export Tool
============================

[](#laravel-eloquent-export-tool)

Give the ability to build profiles/configurations to be used by a artisan command to export data from the database using Eloquent models.

---

**This has only been tested on Laravel 5.1 but it should work on higher versions**

---

### Use case:

[](#use-case)

- Export a user and all there data from a production database and import it into a local database for bug testing/repairing.
- Backup subset of data so that you can easily restore it after testing new features or changes to the data stored in the database.

Composer Install
----------------

[](#composer-install)

Add the fallowing to your `composer.json`

```
{
    "require": {
        "faulker/eloquent-export": "dev-master"
    }
}

```

Add the service provider to `config/app.php`

```
Faulker\EloquentExport\EloquentExportServiceProvider::class,

```

Publish the default config file `config/eloquent-export.php`

```
php artisan vender:publish

```

### 5.1 Notes

[](#51-notes)

Laravel 5.1 dosen't support the ability of getting a list of a Model's casted columns so you will have to add the `Faulker\EloquentExport\EloquentExportTrait` trait to any Model that has `JSON` or `array` casted columns.

```
use Faulker\EloquentExport\EloquentExportTrait;

class MyModel extends Models
{
    use EloquentExportTrait;
    ...
}

```

Profile Creation
----------------

[](#profile-creation)

### Profile Structure

[](#profile-structure)

```
'profile_name' => [
    'model'     => \Name\Space\Root\Model::class,
    'relations' => [
        '[relation]'                  => \Name\Space\Relation\Model::class,
        '[relation].[child_relation]' => \Name\Space\ChildRelation\Model::class,
    ],
],

```

**Example**

```
'user_posts' => [
    'model'     => \Name\Space\EloquentUser::class, // User model (root model)
    'relations' => [
        'posts'         => \Name\Space\Posts::class, // Posts model
        'posts.comment' => \Name\Space\Comments::class, // Comments model
    ],
],

```

The above profile will export a user, all their posts, and all comments for each post.

Usage
-----

[](#usage)

### Base arguments

[](#base-arguments)

```
php artisan export:eloquent [profile] [path_to_file] [--id=] [--import]

```

- \[profile\] - Name of a profile you have created in the `config/eloquent-export.php` file.
- \[path\_to\_file\] - Export/Import file.
- \[--id=\] - Primary ID ($primaryKey) of the root model data you want to export. Exp. if you are exporting a user then it would be the user's ID.
- \[--import\] - Import the data, if not set then data will be exported from the database.

### Example Usage

[](#example-usage)

Export using the `user_posts` profile:

```
php artisan export:eloquent user_posts /tmp/export/user_posts.json --id=34342

```

- The output file is in JSON format

---

Import using the `user_posts` profile:

```
php artisan export:eloquent user_posts /tmp/export/user_posts.json --import

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

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

2

Last Release

3368d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c803cd935b2f0e6aa591e665129780554a799bf967436520bd95efa3a5aa737?d=identicon)[faulker](/maintainers/faulker)

---

Top Contributors

[![faulker](https://avatars.githubusercontent.com/u/2238782?v=4)](https://github.com/faulker "faulker (10 commits)")

---

Tags

laraveldatabasebackupexporteloquentimportrestore

### Embed Badge

![Health badge](/badges/faulker-eloquent-export/health.svg)

```
[![Health](https://phpackages.com/badges/faulker-eloquent-export/health.svg)](https://phpackages.com/packages/faulker-eloquent-export)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[cornford/backup

An easy way backup and restore databases in Laravel.

4225.6k](/packages/cornford-backup)

PHPackages © 2026

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