PHPackages                             laraib15/laravel-schema-generator - 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. laraib15/laravel-schema-generator

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

laraib15/laravel-schema-generator
=================================

Generate Laravel migrations from a schema DSL (create, add, modify, drop columns with DB diffing).

v1.2.0(4mo ago)03MITPHPPHP ^8.1

Since Dec 12Pushed 4mo agoCompare

[ Source](https://github.com/laraib15/laravel-schema-generator-package)[ Packagist](https://packagist.org/packages/laraib15/laravel-schema-generator)[ RSS](/packages/laraib15-laravel-schema-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (0)

Laravel Schema Generator
========================

[](#laravel-schema-generator)

Laravel Schema Generator is a Laravel package that generates migration files using a concise **schema DSL (Domain Specific Language)**.
Based on the DSL and your existing database structure, it determines whether to generate:

- Create table migration
- Add columns migration
- Modify columns migration (DBAL-powered)
- Drop columns migration
- Composite indexes and unique indexes

The generator compares your **DSL schema** against the **actual database schema**, making migration generation predictable and automated.

---

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

[](#requirements)

ComponentSupported VersionsPHP8.1+Laravel9, 10, 11, 12Doctrine DBALOptional — Required only for modify-column supportDatabaseMySQL recommended for modify operations> SQLite does not support `->change()`. Modify-column migrations should be executed on MySQL/PostgreSQL.

---

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

[](#installation)

```
composer require laraib15/laravel-schema-generator --dev
```

Laravel automatically registers the service provider.

The generator command becomes available:

```
php artisan generate:crud
```

If you want modify-column (`->change()`) support, install DBAL in your Laravel app:

```
composer require doctrine/dbal
```

---

Important Notes About Modify-Column Support
-------------------------------------------

[](#important-notes-about-modify-column-support)

Modify-column detection relies on Doctrine DBAL to inspect the **actual database schema**.
Because of this:

### 1. Migrations must be executed before DBAL can detect column types

[](#1-migrations-must-be-executed-before-dbal-can-detect-column-types)

If a migration has **not yet been run**, the table or column will not exist in the database.

In that case, the generator cannot detect the existing column type and will treat it as a **new column**, producing:

```
xxxx_add_columns_to_table.php

```

instead of:

```
xxxx_modify_columns_in_table.php

```

### 2. Modify operations require:

[](#2-modify-operations-require)

- Doctrine DBAL installed
- The table/column already existing in the database

Example:

```
php artisan generate:crud "orders:id:uuid:primary,name:string"
php artisan migrate

php artisan generate:crud "orders:name:text"
```

If you skip `php artisan migrate`, DBAL cannot detect existing columns.

### 3. SQLite cannot run modify migrations

[](#3-sqlite-cannot-run-modify-migrations)

Even with DBAL installed, SQLite does not support `->change()`.
Use MySQL/PostgreSQL for production modify support.

---

Schema DSL Overview
===================

[](#schema-dsl-overview)

The DSL (Domain-Specific Language) format looks like this:

```
table:column:type:option1:option2=value,another_column:type:option,...

```

- Each column definition is separated by commas
- Each option modifies column behavior

---

Supported Column Types
======================

[](#supported-column-types)

```
bigIncrements, bigInteger, binary, boolean,
char, date, datetime, dateTimeTz,
decimal, double, enum, float,
foreignId, geometry, increments, integer,
json, jsonb, longText, mediumText,
morphs, uuidMorphs, smallInteger, tinyInteger,
text, string, set, timestamp, timestampTz,
time, softDeletes, timestamps,
uuid, year

```

---

Column Options
==============

[](#column-options)

OptionExampleMeaningnullable`name:string:nullable`Adds `->nullable()`default`status:string:default=pending`Sets a default valuelength`code:string:20`Defines string lengthcomment`id:uuid:comment=Primary key`Adds column commentunique`email:string:unique`Adds unique indexindex`category:string:index`Adds indexunsigned`age:integer:unsigned`Unsigned integerdrop`status:string:drop`Drops a column---

Foreign Keys
============

[](#foreign-keys)

### Define a foreign key

[](#define-a-foreign-key)

```
user_id:foreignId:constrained=users:onDelete=cascade

```

Generates:

```
$table->foreignId('user_id')
      ->constrained('users')
      ->onDelete('cascade');
```

### Drop a foreign key

[](#drop-a-foreign-key)

```
user_id:foreignId:drop

```

Generates:

```
$table->dropForeign(['user_id']);
$table->dropColumn('user_id');
```

---

Composite Indexes
=================

[](#composite-indexes)

### Unique Index

[](#unique-index)

```
unique:user_id|ordered_at

```

### Index

[](#index)

```
index:category|status

```

---

Usage Examples
==============

[](#usage-examples)

1. Create a New Table
---------------------

[](#1-create-a-new-table)

```
php artisan generate:crud "
orders:
  id:uuid:primary,
  user_id:foreignId:constrained=users:onDelete=cascade,
  status:enum:values=pending|processing|completed:default=pending,
  amount:decimal:precision=10:scale=2,
  timestamps
"
```

Generates:

```
xxxx_create_orders_table.php

```

---

2. Add New Columns
------------------

[](#2-add-new-columns)

```
php artisan generate:crud "orders:tracking_code:string:nullable"
```

Generates:

```
xxxx_add_columns_to_orders_table.php

```

---

3. Modify Column Type (DBAL)
----------------------------

[](#3-modify-column-type-dbal)

```
php artisan generate:crud "orders:status:text"
```

Generates:

```
xxxx_modify_columns_in_orders_table.php

```

Contains:

```
$table->text('status')->change();
```

---

4. Drop Columns
---------------

[](#4-drop-columns)

```
php artisan generate:crud "orders:tracking_code:string:drop"
```

Generates:

```
xxxx_drop_columns_from_orders_table.php

```

---

Auto-Diff Logic
===============

[](#auto-diff-logic)

The generator compares:

```
< DSL schema >      < DB schema >

```

Then decides:

ConditionOutputTable does not existCreate migrationColumn exists in DSL but not DBAdd column migrationColumn type or nullability differsModify migrationColumn removed from DSLDrop migrationNo differencesNo migration created---

Testing
=======

[](#testing)

SQLite Tests (Default)
----------------------

[](#sqlite-tests-default)

```
vendor/bin/phpunit
```

MySQL Integration Tests
-----------------------

[](#mysql-integration-tests)

Enable MySQL tests:

```
CRUD_MYSQL_TEST_ENABLED=true vendor/bin/phpunit --group=mysql
```

Tests cover:

- Modify-column detection
- Doctrine DBAL introspection
- Foreign key dropping
- Combined modify + add sequences

---

License
=======

[](#license)

MIT License

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance74

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

3

Last Release

148d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/11df800067523be8ea8fd1b0d5e021f1923fdbaacc5e40d5eab8015fed731c9b?d=identicon)[laraib15](/maintainers/laraib15)

---

Top Contributors

[![laraib15](https://avatars.githubusercontent.com/u/132258861?v=4)](https://github.com/laraib15 "laraib15 (4 commits)")

---

Tags

laravelmysqlpostgrescrud generatormigration-generatorschema generatorschema dslmigration diff

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laraib15-laravel-schema-generator/health.svg)

```
[![Health](https://phpackages.com/badges/laraib15-laravel-schema-generator/health.svg)](https://phpackages.com/packages/laraib15-laravel-schema-generator)
```

###  Alternatives

[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k25.2M34](/packages/kirschbaum-development-eloquent-power-joins)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[baril/bonsai

An implementation of the Closure Tables pattern for Eloquent.

3593.5k](/packages/baril-bonsai)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)[guanguans/laravel-dump-sql

laravel 中轻松容易的输出完整的 SQL 语句。 - Easy output of complete SQL statements for laravel framework.

3635.6k](/packages/guanguans-laravel-dump-sql)

PHPackages © 2026

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