pxlrbt / laravel-database-state
Seed critical state for your production DBs.
v1.0.5
2024-10-17 15:00 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.13.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
README
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.