PHPackages                             abdelrahmanrafaat/schema-to-code - 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. abdelrahmanrafaat/schema-to-code

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

abdelrahmanrafaat/schema-to-code
================================

Converts DB schema to Laravel code (Migrations &amp; Models)

20133PHP

Since Apr 5Pushed 8y ago3 watchersCompare

[ Source](https://github.com/abdelrahmanrafaat/schema-to-code)[ Packagist](https://packagist.org/packages/abdelrahmanrafaat/schema-to-code)[ RSS](/packages/abdelrahmanrafaat-schema-to-code/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

schema-to-code
==============

[](#schema-to-code)

Laravel Packages for Converting Relational Database schema with a predefined syntax To code (Models &amp; Migrations)

---

### Package Use-cases

[](#package-use-cases)

- If you want a fast way to scaffold your models and migrations without writing bunch of commands and going through multiple files to define relations in the models and migrations
- For example creating MVP or small project and you already have a DB schema in your mind

---

### 1- Package Installation

[](#1--package-installation)

```
  $ composer require abdelrahmanrafaat/schema-to-code:dev-master

```

---

### 2- Package Usage

[](#2--package-usage)

- Create schema file and put it anywhere accessible from the project root directory
- Schema file should be **.txt** extension
- Creating schema.txt in the app directory

```
  $ touch app/schema.txt

```

---

### 3- Write your schema

[](#3--write-your-schema)

- Schema should have even number of non-empty lines

#### Models Syntax

[](#models-syntax)

- line for Models -**Two** models per line seperated by double colon **:** - like one of the following:
- `user:profile``actor:movie``cart:product`

#### Relations Syntax

[](#relations-syntax)

- line for defining the relation between the two models like one of the following:
- `1:1``1:m``m:1``m:m`

---

##### One to One Relation

[](#one-to-one-relation)

- Defining a relation between user and profile as one to one relation
- (**User has one profile** and **Profile belongs to a User**) it will be written like this :

```
  user : profile
    1  :   1

```

---

##### One to Many Relation

[](#one-to-many-relation)

- Defining a relation between user and order as one to many relation
- (**User has many Orders** and **Order belongs to a User**) it will be written like this :

```
  user : order
    1  :   m

```

Or like this :

```
  order : user
    m   :  1

```

---

##### Many to Many Relation

[](#many-to-many-relation)

- Defining a relation between product and cart as many to many relation
- (**Cart has many Product** and **Product can be in multiple Carts**) it will be written like this :

```
  cart : product
    m  :   m

```

Or like this :

```
  cart : product
    m  :   m

```

---

##### An Example for a complete schema

[](#an-example-for-a-complete-schema)

```
User:Profile
1:1

User:Actor
1:1

Actor:Movie
M:m

Movie:Review
1:M

Review:User
M:1

```

---

### 4- Convert Schema to code :

[](#4--convert-schema-to-code-)

- You can replace app/schema.txt with the path to the schema file that you have created earlier

```
  $ php artisan conver:schema-to-code app/schema.txt

```

---

### 5- After the command finishes it will generate a report for the created migrations and models

[](#5--after-the-command-finishes-it-will-generate-a-report-for-the-created-migrations-and-models)

Created Migrations ...create\_users\_tablecreate\_profiles\_tablecreate\_actors\_tablecreate\_movies\_tablecreate\_reviews\_tableupdate\_profiles\_relationsupdate\_actors\_relationscreate\_actors\_movies\_tableupdate\_reviews\_relationsCreated Models ...UserProfileActorMovieReview---

### 6- Migrate

[](#6--migrate)

- Every thing is set now, just run the migrate command to create the tables and relations in your DB

```
  $ php artisan migrate

```

---

### 7- Explore

[](#7--explore)

- Now open the created models in the /app directory to see the methods defined for the relations of each model and to know how to call them in your code
- Open the /database/migrations directory to see the defentations for the relations, and to start adding some fields for every table

---

#### Final Notes :

[](#final-notes-)

- **Be careful : If you have an existing models they will be overridden if they were in the schema file**
- Models are created in /app directory
- Migrations are created in /database/migrations directory
- All the created migrations follows laravel naming conventions and the relations in the models and migrations also follows laravel naming conventions

---

Happy Coding ^\_^

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.6% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17337459?v=4)[abdelrahmanrafaat](/maintainers/abdelrahmanrafaat)[@abdelrahmanrafaat](https://github.com/abdelrahmanrafaat)

---

Top Contributors

[![abdelrahmanrafaat](https://avatars.githubusercontent.com/u/17337459?v=4)](https://github.com/abdelrahmanrafaat "abdelrahmanrafaat (19 commits)")[![abdelrahmanrafat](https://avatars.githubusercontent.com/u/36039430?v=4)](https://github.com/abdelrahmanrafat "abdelrahmanrafat (4 commits)")

### Embed Badge

![Health badge](/badges/abdelrahmanrafaat-schema-to-code/health.svg)

```
[![Health](https://phpackages.com/badges/abdelrahmanrafaat-schema-to-code/health.svg)](https://phpackages.com/packages/abdelrahmanrafaat-schema-to-code)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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