PHPackages                             kogoshvili/meloq - 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. kogoshvili/meloq

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

kogoshvili/meloq
================

Migration generator for Laravel

01PHP

Since Mar 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Kogoshvili/Meloq)[ Packagist](https://packagist.org/packages/kogoshvili/meloq)[ RSS](/packages/kogoshvili-meloq/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Meloq (beta)
============

[](#meloq-beta)

Meloq is a migration generator for Laravel. It generates migration files based on model definitions, and uses PHP attributes and type hints to infer the database schema.

Example
-------

[](#example)

Model definitions:

```
#[Table(primary: "id")]
class Book extends Model
{
    public int $id;
    #[Column(name: "Author")]
    public string $author;
    #[Column(name: "Title")]
    public string $title;
    public Status $status;
    public function authors(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
    {
        return $this->belongsToMany(Author::class);
    }
}

enum Status
{
    case DRAFT;
    case PUBLISHED;
    case ARCHIVED;
}

class Author extends Model
{
    public string $name;
    #[Primary]
    public int $author_id;
    public function books() : \Illuminate\Database\Eloquent\Relations\HasMany
    {
        return $this->hasMany(Book::class);
    }
}
```

Migration files generated:

```
Schema::create('authors', function (Blueprint $table) {
    $table->integer('id');
    $table->string('name');
    $table->integer('author_id')->unique()->primary()->autoIncrement()->index();
});
Schema::create('books', function (Blueprint $table) {
    $table->string('Author');
    $table->string('Title');
    $table->enum('status', ['DRAFT', 'PUBLISHED', 'ARCHIVED']);
    $table->integer('id');
    $table->primary('id');
});
```

Setup
-----

[](#setup)

install the package:

```
composer require kogoshvili/meloq:dev-main
```

add the service provider to the providers array in config/app.php:

```
'providers' => ServiceProvider::defaultProviders()->merge([
    //...
    Kogoshvili\Meloq\MeloqServiceProvider::class,
])->toArray(),
```

publish the config file (optional):

```
php artisan vendor:publish --tag=meloq-config
```

Usage
-----

[](#usage)

When first time using Meloq, you need to record the model definitions, without creating the migration files. Run the following command to generate json model definitions, that are used to generate migration files and keep track of the changes:

```
php artisan meloq:record
```

Run the following command to generate migration files based on the recorded model definitions:

```
php artisan meloq:migrate
```

### Defining Model

[](#defining-model)

Meloq uses PHP attributes and type hints to infer the database schema.

Type Hints example:

```
public int $id; => $table->integer('id');
public ?string $name; => $table->string('name')->nullable();
public int $total = 0; => $table->integer('total')->default(0);
```

Attributes example:

```
#[Column(name: "Author", type: "string", nullable: true)]
public string $author; => $table->string('Author')->nullable();
```

### Attributes

[](#attributes)

```
#[Column(name: "Author", type: "string", nullable: true)]
public string $author; => $table->string('Author')->nullable();
```

```
#[Table(name: "books", primary: "id")]
```

- name: table name (default: plural of the model class name)
- primary: primary key column name (default: null)

```
#[Column(name: "author", type: "string", comment: null, precision: null, scale: null, nullable: false, unique: false, primary: false, increment: false, index: false, default: null, value: null, foreignKey: null, referenceKey: null, referenceTable: null)]
```

- name: column name (default: property name)
- type: column type (default: type hint, e.g. int -&gt; integer, string -&gt; string)
- comment: column comment (default: null)
- precision: column precision (default: null)
- scale: column scale (default: null)
- nullable: whether the column is nullable (default: ?type hint, e.g. ?int -&gt; true, int -&gt; false)
- unique: whether the column is unique (default: false)
- primary: whether the column is primary key (default: false)
- increment: whether the column is auto increment (default: false)
- index: whether the column is indexed (default: false)
- default: default value (default: null)
- value: column value (default: null)
- foreignKey: foreign key column name (default: null)
- referenceKey: reference key column name (default: null)
- referenceTable: reference table name (default: null)

```
#[Timestamp(name: "created_at", precision: 0)]
```

- name: column name (default: property name)
- precision: timestamp precision (default: 0)

```
#[Primary(name: "author_id", type: "int", increment: true, comment: null)]
```

- name: column name (default: property name)
- type: column type (default: type hint, e.g. int -&gt; integer, string -&gt; string)
- increment: whether the column is auto increment (default: false)
- comment: column comment (default: null)

```
#[Ignore]
```

- Ignore the property from the model definition.

### Relations

[](#relations)

Meloq relies on the return type of the relation methods to infer the relation type, so return type must be explicitly defined. E.g

```
public function license() : \Illuminate\Database\Eloquent\Relations\HasOne
{
    return $this->hasOne(License::class);
}
public function appointments() : \Illuminate\Database\Eloquent\Relations\HasMany
{
    return $this->hasMany(Appointment::class);
}
```

```
Schema::create('licenses', function (Blueprint $table) {
    $table->foreignId('client_id')->references('id')->on('drivers');
});
Schema::create('appointments', function (Blueprint $table) {
    $table->foreignId('doctor_id')->references('id')->on('doctors');
});
```

Quirks
------

[](#quirks)

- Don't define id column with BelongsToMany relation, or you will get "Typed property App\\Models\\Book::$id must not be accessed before initialization" error. Instead, define primary key in the Table attribute, e.g.

```
#[Table(primary: "id")]
class Book extends Model
{
    // public int $id
    public function authors(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
    {
        return $this->belongsToMany(Author::class);
    }
}
```

Todos
-----

[](#todos)

- Add support for on delete and on update actions for foreign keys.
- Add support for after and before actions for columns.
- Figure out how to fix Quirks.

###  Health Score

12

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity19

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/eeead026c18d6fb35c3f89cc0fd306b2329f776bb4b9edd24d1514e42842806b?d=identicon)[kogoshvili](/maintainers/kogoshvili)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/kogoshvili-meloq/health.svg)

```
[![Health](https://phpackages.com/badges/kogoshvili-meloq/health.svg)](https://phpackages.com/packages/kogoshvili-meloq)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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