mybizna / automigrator
Declare database migrations and factory definitions inside Laravel models.
Requires
- doctrine/dbal: ^2.0|^3.0
- laravel/framework: ^7.0|^8.0|^9.0|^10.0
- dev-main
- 24.2.002
- 24.02.001
- 23.12.001
- 23.11.001
- 23.07.0
- 23.06.0
- 1.3.58
- 1.3.56
- 1.3.55
- 1.3.54
- 1.3.53
- 1.3.52
- 1.3.51
- 1.3.50
- 1.3.49
- 1.3.48
- 1.3.47
- 1.3.46
- 1.3.45
- 1.3.44
- 1.3.43
- 1.3.42
- 1.3.41
- 1.3.40
- 1.3.39
- 1.3.38
- 1.3.37
- 1.3.36
- 1.3.35
- 1.3.34
- 1.3.33
- 1.3.32
- 1.3.31
- 1.3.30
- 1.3.29
- 1.3.28
- 1.3.27
- 1.3.26
- 1.3.25
- 1.3.24
- 1.3.23
- 1.3.22
- 1.3.20
- 1.3.19
- 1.3.18
- 1.3.17
- 1.3.16
- 1.3.15
- 1.3.14
- 1.3.13
- 1.3.12
- 1.3.10
- 1.3.9
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.99
- 1.2.98
- 1.2.97
- 1.2.96
- 1.2.95
- 1.2.94
- 1.2.93
- 1.2.92
- 1.2.91
- 1.2.90
- 1.2.88
- 1.2.87
- 1.2.86
- 1.2.85
- 1.2.84
- 1.2.83
- 1.2.82
- 1.2.81
- 1.2.80
- 1.2.79
- 1.2.78
- 1.2.77
- 1.2.76
- 1.2.75
- 1.2.74
- 1.2.73
- 1.2.72
- 1.2.71
- 1.2.70
- 1.2.69
- 1.2.68
- 1.2.67
- 1.2.66
- 1.2.65
- 1.2.64
- 1.2.63
- 1.2.62
- 1.2.61
- 1.2.60
- 1.2.59
- 1.2.58
- 1.2.57
- 1.2.56
- 1.2.54
- 1.2.53
- 1.2.52
- 1.2.51
- 1.2.50
- 1.2.49
- 1.2.48
- 1.2.47
- 1.2.46
- 1.2.45
- 1.2.44
- 1.2.43
- 1.2.42
- 1.2.41
- 1.2.40
- 1.2.39
- 1.2.38
- 1.2.37
- 1.2.36
- 1.2.35
- 1.2.34
- 1.2.33
- 1.2.32
- 1.2.31
- 1.2.30
- 1.2.29
- 1.2.28
- 1.2.27
- 1.2.26
- 1.2.25
- 1.2.24
- 1.2.23
- 1.2.22
- 1.2.21
- 1.2.20
- 1.2.19
- 1.2.18
- 1.2.17
- 1.2.16
- 1.2.15
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-master
This package is auto-updated.
Last update: 2024-11-04 13:04:28 UTC
README
This package allows you to declare database migrations and factory definitions inside of your Laravel models.
Running the automigrator:migrate
command will automatically apply any changes you've made inside your migration
methods to the database via Doctrine DBAL. If using the HasNewFactory
trait and definition
method, it will use the returned array inside the definition
method to seed with when using the -s
option.
The automigrator:migrate
command will also run your file-based (traditional) Laravel migrations first, and then your model method migrations after. If you need your model-based migrations to run in a specific order, you may add a $migrationOrder
property to your models with an integer value (default is 0
).
Installation
Require this package via Composer:
composer require mybizna/automigrator
Usage
Use the HasNewFactory
trait, and declare migration
and definition
methods in your models:
use Faker\Generator; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; use Mybizna\Automigrator\Traits\HasNewFactory; class MyModel extends Model { use HasNewFactory; protected $guarded = []; protected $migrationOrder = 1; // optional public function migration(Blueprint $table) { $table->id(); $table->string('name'); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable(); } public function definition(Generator $faker) { return [ 'name' => $faker->name(), 'created_at' => $faker->dateTimeThisMonth(), ]; } }
Commands
Migrating
Apply the changes inside your migration
methods to your database:
php artisan automigrator:migrate {--f|--fresh} {--s|--seed}
Use the -f
option for fresh migrations, and/or the -s
option to run seeders afterwards.
Making Models
Create a model containing the migration
and definition
methods:
php artisan automigrator:model {name} {--r|--resource}
Use the -r
option to create a Laravel Nova resource for the model at the same time.
Making Nova Resources
Create a Laravel Nova resource without all the comments:
php artisan automigrator:resource {name} {--m|--model}
Use the -m
option to create a model for the Nova resource at the same time.