Seed critical state your databases with production data.
Find a file
2026-10-07 07:03:36 +00:00
.github Remove Dependabot, Renovate takes over 2026-10-07 07:03:36 +00:00
config wip 2023-08-08 16:38:13 +02:00
src Add test suite and modernize dev dependencies 2026-03-23 19:30:58 +01:00
stubs Initial 2023-08-08 16:31:11 +02:00
tests Convert tests from PHPUnit to Pest 2026-03-23 19:35:59 +01:00
.editorconfig Initial 2023-08-08 16:31:11 +02:00
.gitattributes Initial 2023-08-08 16:31:11 +02:00
.gitignore Initial 2023-08-08 16:31:11 +02:00
composer.json Convert tests from PHPUnit to Pest 2026-03-23 19:35:59 +01:00
LICENSE.md Initial 2023-08-08 16:31:11 +02:00
phpstan-baseline.neon Initial 2023-08-08 16:31:11 +02:00
phpstan.neon.dist Add test suite and modernize dev dependencies 2026-03-23 19:30:58 +01:00
phpunit.xml.dist Add test suite and modernize dev dependencies 2026-03-23 19:30:58 +01:00
README.md stancl/tenancy support 2023-08-08 17:11:47 +02:00

Laravel Database State

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Seed critical state your databases with production data.

Installation

You can install the package via composer:

composer require pxlrbt/laravel-database-state

Add autoloader

Add the Database\States namespace to the composer.json

{
    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/",
            "Database\\States\\": "database/states/"
        }
    }
}

Create your first database state

You can create a new class via CLI: php artisan make:db-state. This will create an invokable class in database/States directory.

Make sure your database states are idempotent, so consecutive runs won't create duplicate entries or overwrite existing entries.

<?php
namespace Database\States;

use App\Models\User;

class UserState
{
    public function __invoke()
    {
        if (! User::where('user', 'info@example.com')->exists()) {
            User::forceCreate([
                'name' => 'Example User',
                'email' => 'info@example.com',
                'email_verified_at' => now(),
                'password' => '$2y$10$etbrxzCyYhs598Abu6XdAeJ7GZQvDhOvE70XnRtoO25bvif1uEvSi',
            ]);
        }
    }
}

Credits

License

The MIT License (MIT). Please see License File for more information.