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

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

dandoetech/laravel-model-meta
=============================

Laravel bridge for code generation (models, migrations) from Resource Registry definitions.

v0.2.0(2d ago)20MITPHPPHP ^8.2CI passing

Since Mar 15Pushed 2d agoCompare

[ Source](https://github.com/dandoetech/laravel-model-meta)[ Packagist](https://packagist.org/packages/dandoetech/laravel-model-meta)[ Docs](https://github.com/dandoetech/laravel-model-meta)[ RSS](/packages/dandoetech-laravel-model-meta/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (10)Versions (3)Used By (0)

Laravel Model Meta
==================

[](#laravel-model-meta)

> **Pre-release** — Architecture by senior tech lead, implementation largely AI-assisted with human review. Not fully reviewed. Architecture may change before v1.0.0.

Generate Eloquent Models and Migrations from Resource Registry definitions. Also provides model introspection for the OpenAPI generator.

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

[](#installation)

```
composer require dandoetech/laravel-model-meta
```

The service provider is auto-discovered. Publish the config:

```
php artisan vendor:publish --tag=model-meta-config
```

Requires [`dandoetech/laravel-resource-registry`](https://github.com/dandoetech/laravel-resource-registry).

Quick Start
-----------

[](#quick-start)

Given a resource definition:

```
class ProductResource extends Resource implements HasEloquentModel
{
    public function model(): string { return \App\Models\Product::class; }

    protected function define(ResourceBuilder $b): void
    {
        $b->key('product')
          ->label('Product')
          ->timestamps()
          ->softDeletes()
          ->field('name', FieldType::String, nullable: false, rules: ['required', 'max:120'])
          ->field('price', FieldType::Float, nullable: false)
          ->field('category_id', FieldType::Integer, nullable: false)
          ->belongsTo('category', foreignKey: 'category_id')
          ->action('create')
          ->action('update');
    }
}
```

Generate the model and migration:

```
php artisan model-meta:generate-models
php artisan model-meta:generate-migrations
```

### Generated Model

[](#generated-model)

```
