PHPackages                             laragear/meta-model - 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. laragear/meta-model

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

laragear/meta-model
===================

Let other developers customize your package model and migrations

v3.0.0(2mo ago)1861.7k—2.9%17MITPHPPHP ^8.3CI passing

Since Mar 12Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Laragear/MetaModel)[ Packagist](https://packagist.org/packages/laragear/meta-model)[ Fund](https://github.com/sponsors/DarkGhostHunter)[ Fund](https://paypal.me/darkghosthunter)[ RSS](/packages/laragear-meta-model/feed)WikiDiscussions 3.x Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (14)Used By (7)

Meta Model
==========

[](#meta-model)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ee57880cb48f144d0d8aaa4e63c187a0cc89a0d4644859c9bd8c5cb7039485f3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c617261676561722f6d6574612d6d6f64656c2e737667)](https://packagist.org/packages/laragear/meta-model)[![Latest stable test run](https://github.com/Laragear/MetaModel/workflows/Tests/badge.svg)](https://github.com/Laragear/MetaModel/actions)[![codecov](https://camo.githubusercontent.com/a450898e70e0ccf5d4fdecd223700f7a1e1dc588d82d4b82183fb1fd64d2d5ee/68747470733a2f2f636f6465636f762e696f2f67682f4c617261676561722f4d6574614d6f64656c2f67726170682f62616467652e7376673f746f6b656e3d6646373452703075576e)](https://codecov.io/gh/Laragear/MetaModel)[![Maintainability](https://camo.githubusercontent.com/e28e0fc0e1b809b29bebf3926aa068eb7dfcf16f3a0c3909ff6a823ad1ad4792/68747470733a2f2f716c74792e73682f6261646765732f30363738626337652d373930302d346531372d393033382d6363633065386662326235362f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/Laragear/projects/MetaModel)[![Sonarcloud Status](https://camo.githubusercontent.com/549f0f2cd8697edb4797a0f9b1d52fddaf0945169cff2af4637656ffc783262d/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d4c617261676561725f4d6574614d6f64656c266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Laragear_MetaModel)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/13.x/octane#introduction)

Let other developers customize your package model and migrations.

```
namespace Vendor\Package\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Laragear\MetaModel\CustomMigration;
use Laragear\MetaModel\HasCustomization;

class MyPackageModel extends Model
{
    use HasCustomization;

    protected static function migration(): string
    {
        return CustomMigration::make(function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->timestamps();
        })
    }
}
```

Tip

Did you come here from a package? You probably want to read the [DATABASE.md](DATABASE.md) file instead.

Keep this package free
----------------------

[](#keep-this-package-free)

[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can **[spread the word!](http://twitter.com/share?text=I%20am%20using%20this%20cool%20PHP%20package&url=https://github.com%2FLaragear%2FMetaModel&hashtags=PHP,Laravel)**

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

[](#requirements)

- PHP 8.3 or later
- Laravel 12 or later

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

[](#installation)

Fire up Composer and require it into your package:

```
composer require laragear/meta-model
```

Customizing models
------------------

[](#customizing-models)

When you create a model in your package, your end-developers won't be able to modify it unless they create a repository that manually creates a model, which is cumbersome. Instead, you can add the `HasCustomization` trait to your model and let the developer modify the model when is instanced with a simple callback.

```
namespace Vendor\Package\Models;

use Illuminate\Database\Eloquent\Model;
use Laragear\MetaModel\HasCustomization;

class Car extends Model
{
    use HasCustomization;

    // ...
}
```

Tip

The trait methods are marked as "internal" to avoid appearing on the end-developer IDE.

From there, the end-developer can customize the model by setting a callback to the `customize()` method. The callback receives the model instance. For example, they can do this in the `bootstrap/app.php` file, through the `booted()` method.

```
use Vendor\Package\Models\Car;

use Illuminate\Foundation\Application;

return Application::booted(function () {

    Car::customize(function ($model) {
        $model->setTable('vendor_cars');
        $model->setConnection('read-database');
    });

})->create();
```

Custom Migration
----------------

[](#custom-migration)

You may use the `makeMigrations()` method of the trait to create an already-made migration. In other words, the end-developers receive a working migration that can modify or extend at their leisure.

Simply use the `make()` method of the `Laragear\MetaModel\CustomMigration` class with a callback to create the table. The table name is retrieved automatically from the Model `getTable()` method, and it will be correctly dropped when invoking `down()` later in the migration file.

```
namespace Vendor\Package\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Laragear\MetaModel\CustomMigration;
use Laragear\MetaModel\HasCustomization;
use MyVendor\MyPackage\Models\Car;

class Car extends Model
{
    use HasCustomization;

    public static function makeMigrations(): CustomMigration|array
    {
        return CustomMigration::make(function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->timestamps();
        });
    }
}
```

Tip

Inside the callback, `$this` is bound to the `CustomMigration` instance, not the model.

Once done, create the migration file, like `0000_00_00_000000_create_cars_table.php`. Instead of returning a class that extends the default Laravel migration, we use our model and the `migration()` method.

```
// database/migrations/0000_00_00_000000_create_cars_table.php
use Vendor\Package\Models\Car;

return Car::migration();
```

### Multiple migrations

[](#multiple-migrations)

If you require to handle multiple migrations for a model, simple return an `array` of migrations, and separate each Custom migration using the `table` argument. This is not necessary for the default migration, only for the additional ones.

```
namespace Vendor\Package\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Laragear\MetaModel\CustomMigration;
use Laragear\MetaModel\HasCustomization;
use MyVendor\MyPackage\Models\Car;

class Car extends Model
{
    use HasCustomization;

    public static function makeMigrations(): CustomMigration|array
    {
        return [
            CustomMigration::make(function (Blueprint $table) {
                // ...
            }),
            CustomMigration::make(function (Blueprint $table) {
                // ...
            }, table: 'car_repairs'),
        ];
    }
}
```

To return a non-default migration, simply use the `migration()` method with the respective table name. If no name is issued, the "default" migration (that uses the Model defined table) will be returned.

```
// database/migrations/0000_00_00_000000_create_cars_table.php
use MyVendor\MyPackage\Models\Car;

return Car::migration();
```

```
// database/migrations/0000_00_00_000000_create_car_repairs_table.php
use MyVendor\MyPackage\Models\Car;

return Car::migration('car_repairs');
```

### Morphs

[](#morphs)

Caution

Morphs are only supported for a single relation. Multiple morphs relations on a single table is **highly discouraged**.

If your migration requires morph relationships, you will find that end-developers won't always have the same key type in their application to associate with. This problem can be fixed by using the `createMorph()` or `createNullableMorph()` method with the `Blueprint` instance and the name of the morph type.

```
use Laragear\MetaModel\CustomMigration;

public static function migration(): CustomMigration
{
    return CustomMigration::make(function (Blueprint $table) {
        $table->id();

        $this->createMorph($table, 'ownable');

        $table->string('manufacturer');
        $table->string('model');
        $table->tinyInteger('year');

        $table->timestamps();
    });
}
```

This will let the end-developer to change the morph type through the `morph()` method if needed. For example, if he's using ULID morphs for the target models, he may set it in one line:

```
// database/migrations/0000_00_00_000000_create_cars_table.php
use Vendor\Package\Models\Car;

return Car::migration()->morph('ulid', 'custom_index_name');
```

#### Default index name

[](#default-index-name)

You may also set a custom index name for the morph. It will be used as a default, unless the end-developer overrides it manually.

```
use Laragear\MetaModel\CustomMigration;

public static function migration(): CustomMigration
{
    return CustomMigration::make(function (Blueprint $table) {
        // ...

        $this->createMorphRelation($table, 'ownable', 'ownable_table_index');
    }
}
```

```
// database/migrations/0000_00_00_000000_create_cars_table.php
use Vendor\Package\Models\Car;

// Uses "custom_index_name" as index name
return Car::migration()->morph('ulid', 'custom_index_name');

// Uses "ownable_table_index" as index name
return Car::migration()->morph('ulid');
```

### After Up &amp; Before Down

[](#after-up--before-down)

An end-developer can execute logic after the table is created, and before the table is dropped, using the `afterUp()` and `beforeDown()` methods, respectively. This allows the developer to run enhance the table, or avoid failing migrations due to dependencies (like linked columns, views or else).

For example, the end-developer can use these methods to create foreign column references, and remove them before dropping the table.

```
use MyVendor\MyPackage\Models\Car;
use Illuminate\Database\Schema\Blueprint;

return Car::migration()
    ->afterUp(function (Blueprint $table) {
        $table->foreign('manufacturer')->references('name')->on('manufacturers');
    })
    ->beforeDown(function (Blueprint $table) {
         $table->dropForeign('manufacturer');
    });
```

Important

The `afterUp()` and `beforeDown()` adds callbacks to the migration, it doesn't replace them.

Package documentation
---------------------

[](#package-documentation)

If you plan to add migrations to your package, you may also want to copy-and-paste the [DATABASE.md](DATABASE.md) file in your package root. This way developers will know how to use your model and migrations. Alternatively, you may also just copy its contents, or link back to this repository.

For convenience, you may execute this from your project root:

```
cp vendor/laragear/meta-model/DATABASE.md ./DATABASE.md
```

Laravel Octane compatibility
----------------------------

[](#laravel-octane-compatibility)

- There are no singletons using a stale application instance.
- There are no singletons using a stale config instance.
- There are no singletons using a stale request instance.
- Trait static properties are only written once by end-developer.

There should be no problems using this package with Laravel Octane.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
=======

[](#license)

This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at time of publishing.

[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011-2025 Laravel LLC.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance85

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 97.3% 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 ~103 days

Total

8

Last Release

75d ago

Major Versions

v1.1.1 → v2.0.02025-02-16

2.x-dev → v3.0.02026-03-04

PHP version history (3 changes)v1.0.0PHP ^8.1

v2.0.0PHP ^8.2

v3.0.0PHP ^8.3

### Community

Maintainers

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

---

Top Contributors

[![DarkGhostHunter](https://avatars.githubusercontent.com/u/5141911?v=4)](https://github.com/DarkGhostHunter "DarkGhostHunter (36 commits)")[![it-can](https://avatars.githubusercontent.com/u/644288?v=4)](https://github.com/it-can "it-can (1 commits)")

---

Tags

databaseeloquentlaragearlaravelmodelslaraveldatabasemodeleloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laragear-meta-model/health.svg)

```
[![Health](https://phpackages.com/badges/laragear-meta-model/health.svg)](https://phpackages.com/packages/laragear-meta-model)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M25](/packages/silber-bouncer)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)[friendsofcat/laravel-couchbase

A Couchbase based Eloquent model and Query builder for Laravel

1430.8k](/packages/friendsofcat-laravel-couchbase)

PHPackages © 2026

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