PHPackages                             oi-lab/oi-laravel-seeds - 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. oi-lab/oi-laravel-seeds

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

oi-lab/oi-laravel-seeds
=======================

Export and import Laravel seeders to/from JSON files with dependency management

v1.0.8(3w ago)157MITPHPPHP ^8.2CI failing

Since Oct 31Pushed 3w agoCompare

[ Source](https://github.com/oi-lab/oi-laravel-seeds)[ Packagist](https://packagist.org/packages/oi-lab/oi-laravel-seeds)[ RSS](/packages/oi-lab-oi-laravel-seeds/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (4)Dependencies (10)Versions (9)Used By (0)

[![OI Laravel Seeds](./assets/github-preview.png)](./assets/github-preview.png)

OI Laravel Seeds
================

[](#oi-laravel-seeds)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4e855dc1ad747dcce47a1066f2e61060d32ef80967b0c056eb2e69a71a2f3ec3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f692d6c61622f6f692d6c61726176656c2d73656564732e737667)](https://packagist.org/packages/oi-lab/oi-laravel-seeds)[![Total Downloads](https://camo.githubusercontent.com/01fc09f222e2e98ed4f38e4b8c0eb27df1717370259b363e2bd7a1ea1dd95280/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f692d6c61622f6f692d6c61726176656c2d73656564732e737667)](https://packagist.org/packages/oi-lab/oi-laravel-seeds)[![Tests](https://camo.githubusercontent.com/b28296925a14f98124ab4762272754093827398b730542192ecaaee1e9c6b23e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f692d6c61622f6f692d6c61726176656c2d73656564732f74657374732e796d6c3f6c6162656c3d7465737473)](https://github.com/oi-lab/oi-laravel-seeds/actions)[![License](https://camo.githubusercontent.com/1e04d17dfb469b29a5698efa0bbd5d3765cde047983465392ab3dea8e3558d7c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f692d6c61622f6f692d6c61726176656c2d7365656473)](LICENSE)

A Laravel package to export and import seeders to/from JSON files with intelligent dependency management.

Features
--------

[](#features)

- **JSON Export/Import**: Round-trip database data through portable, version-controllable JSON files
- **Idempotent Imports**: Rows are upserted by a unique key, so re-running never duplicates data
- **Dependency Resolution**: Seeders declare dependencies, ordered automatically via topological sort
- **Relations**: Export models together with their relations using `--with-relations`
- **Multiple Models**: Export/import several models from a single seeder
- **Generator Command**: Scaffold exportable seeders with one artisan command
- **Configurable**: Storage paths, default unique key, auto-discovery, and JSON encoding options

How It Works
------------

[](#how-it-works)

1. **Export**: The package scans your seeders for those using the `ExportableSeeder` trait
2. **Dependencies**: It resolves dependencies using a topological sort to ensure correct order
3. **Export Data**: Each seeder exports its model data to a JSON file in the configured storage path
4. **Import**: When importing, dependencies are processed first, then data is upserted using `updateOrCreate`

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11.0+ or 12.0+

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

[](#installation)

Install the package via composer:

```
composer require oi-lab/oi-laravel-seeds
```

The package auto-discovers and registers its service provider — no manual registration required.

### Local Development

[](#local-development)

For local development inside the monorepo, add a path repository to your main project's `composer.json`:

```
{
    "repositories": [
        {
            "type": "path",
            "url": "./packages/oi-lab/oi-laravel-seeds"
        }
    ]
}
```

### Publish

[](#publish)

Publish the configuration file (optional):

```
php artisan vendor:publish --tag=oi-laravel-seeds-config
```

Publish the seeder stubs (optional):

```
php artisan vendor:publish --tag=oi-laravel-seeds-stubs
```

Usage
-----

[](#usage)

### Creating an Exportable Seeder

[](#creating-an-exportable-seeder)

Generate a new exportable seeder using the artisan command:

```
php artisan make:exportable-seeder GroupSeeder --model=Group --unique-by=name
```

Options:

- `--model` or `-m`: The model class to use for this seeder
- `--unique-by` or `-u`: The unique column(s) for upsert operations (default: id)
- `--json-filename` or `-j`: The JSON filename for export/import

This will create a seeder class like:

```
