PHPackages                             will2therich/laravel-model-migrations - 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. will2therich/laravel-model-migrations

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

will2therich/laravel-model-migrations
=====================================

Declare database migrations and factory definitions inside Laravel models.

2.0.2(6mo ago)1425MITPHP

Since Apr 26Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/will2therich/laravel-model-migrations)[ Packagist](https://packagist.org/packages/will2therich/laravel-model-migrations)[ RSS](/packages/will2therich-laravel-model-migrations/feed)WikiDiscussions master Synced 1mo ago

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

[![LaravelModelMigrations](https://camo.githubusercontent.com/ffa20c86a2bad8140b0faf8f42f7018cdc7d2e1e698b75b8aa89a8fc5ba410dd/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304d6f64656c2532304d6967726174696f6e732e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d2b77696c6c32746865726963682532466c61726176656c2d6d6f64656c2d6d6967726174696f6e73267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d4465636c6172652b64617461626173652b6d6967726174696f6e732b616e642b666163746f72792b646566696e6974696f6e732b696e736964652b4c61726176656c2b6d6f64656c732e266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/ffa20c86a2bad8140b0faf8f42f7018cdc7d2e1e698b75b8aa89a8fc5ba410dd/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532304d6f64656c2532304d6967726174696f6e732e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d2b77696c6c32746865726963682532466c61726176656c2d6d6f64656c2d6d6967726174696f6e73267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d4465636c6172652b64617461626173652b6d6967726174696f6e732b616e642b666163746f72792b646566696e6974696f6e732b696e736964652b4c61726176656c2b6d6f64656c732e266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

Laravel Automatic Model Migrations
==================================

[](#laravel-automatic-model-migrations)

This package is a continuation of `legodion/lucid` which is no longer available

This package allows you to declare database migrations and factory definitions inside of your Laravel models.

Running the `lmm: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 `lmm: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
------------

[](#installation)

Require this package via Composer:

```
composer require will2therich/laravel-model-migrations
```

Usage
-----

[](#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 will2therich\LaravelModelMigrations\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
--------

[](#commands)

### Migrating

[](#migrating)

Apply the changes inside your `migration` methods to your database:

```
php artisan lmm:migrate {--f|--fresh} {--s|--seed}
```

Use the `-f` option for fresh migrations, and/or the `-s` option to run seeders afterwards.

### Making Models

[](#making-models)

Create a model containing the `migration` and `definition` methods:

```
php artisan lmm:model {name} {--r|--resource}
```

Use the `-r` option to create a Laravel Nova resource for the model at the same time.

### Making Nova Resources

[](#making-nova-resources)

Create a Laravel Nova resource without all the comments:

```
php artisan lmm:resource {name} {--m|--model}
```

Use the `-m` option to create a model for the Nova resource at the same time.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance68

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.9% 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 ~141 days

Total

5

Last Release

187d ago

Major Versions

1.0.0 → 2.0.02024-04-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/10797b4583c2ea8930c9224c9262c21f26789005a197243eeaf58a56ad8c0424?d=identicon)[will2therich](/maintainers/will2therich)

---

Top Contributors

[![will2therich](https://avatars.githubusercontent.com/u/24435180?v=4)](https://github.com/will2therich "will2therich (10 commits)")[![jeffersongoncalves](https://avatars.githubusercontent.com/u/411493?v=4)](https://github.com/jeffersongoncalves "jeffersongoncalves (1 commits)")

---

Tags

phplaravelfactorydatabaseeloquentmigrationsmodelsdefinitions

### Embed Badge

![Health badge](/badges/will2therich-laravel-model-migrations/health.svg)

```
[![Health](https://phpackages.com/badges/will2therich-laravel-model-migrations/health.svg)](https://phpackages.com/packages/will2therich-laravel-model-migrations)
```

###  Alternatives

[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[umbrellio/laravel-pg-extensions

Extensions for Postgres Laravel

102426.5k1](/packages/umbrellio-laravel-pg-extensions)[wayofdev/laravel-cycle-orm-adapter

🔥 A Laravel adapter for CycleORM, providing seamless integration of the Cycle DataMapper ORM for advanced database handling and object mapping in PHP applications.

3516.7k3](/packages/wayofdev-laravel-cycle-orm-adapter)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

823.1k](/packages/waad-laravel-model-metadata)[jrsaunders/shard-matrix

A Complete Database Sharding system for MYSQL and/or Postgres. Using Laravels Query Builder easily scale up your application. Configure your whole solution in one Yaml Config file.

271.5k](/packages/jrsaunders-shard-matrix)

PHPackages © 2026

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