PHPackages                             crucialdigital/metamorph - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. crucialdigital/metamorph

ActiveLibrary[HTTP &amp; Networking](/categories/http)

crucialdigital/metamorph
========================

Package of data models managements

3.0.0(1y ago)31.7kMITPHPPHP ^8.1|8.2|8.3

Since Apr 4Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/crucialdigital/metamorph)[ Packagist](https://packagist.org/packages/crucialdigital/metamorph)[ Docs](https://github.com/crucialdigital/metamorph)[ RSS](/packages/crucialdigital-metamorph/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (17)Versions (9)Used By (0)

Crucial Digital Metamorph
=========================

[](#crucial-digital-metamorph)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0fa3b9c2a2b1990269ac6dc4bed740921f4b47b3c5ae1bcbf0e783928de97bb8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6372756369616c6469676974616c2f6d6574616d6f7270682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crucialdigital/metamorph)[![GitHub Tests Action Status](https://camo.githubusercontent.com/a4cb31490a989deecb0e4f67cf3a1bf7bfbf291f0f36ceb7aac987338fb2c74f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6372756369616c6469676974616c2f6d6574616d6f7270682f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/crucialdigital/metamorph/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/f38aaede741d3102abb1d92d187834c79f8c98750f1c25c25def93981e20592b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6372756369616c6469676974616c2f6d6574616d6f7270682f466978253230504850253230636f64652532307374796c652532306973737565733f6c6162656c3d636f64652532307374796c65)](https://github.com/crucialdigital/metamorph/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/166090127b3a67c4c76557a14bd154068659fffd094d545dedc452964f122fb1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6372756369616c6469676974616c2f6d6574616d6f7270682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/crucialdigital/metamorph)

Metamorph is a Laravel package that implements a data model system based on mongodb. This package provides a powerful system for managing dynamically models for api development.

Before going any further, consider that this package is intended for API development with Laravel and Mongodb

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Creating Model, Repository and data model](#creating-model-repository-and-data-model)
    - [Configure data model into metamorph config file](#configure-data-model-into-metamorph-config-file)
    - [Run your data models](#run-your-data-models)
    - [Make API requests](#make-api-requests)
- [Advanced](#advanced)
    - [Global Middleware](#global-middleware)
    - [Model Middleware](#model-middleware)
    - [Policies](#policies)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

You can install the package via composer:

```
composer require crucialdigital/metamorph
```

You must now publish the config file with:

```
php artisan vendor:publish --tag="metamorph-config"
```

Usage
-----

[](#usage)

### Creating Model Repository and data model

[](#creating-model-repository-and-data-model)

Create your data model files with artisan command:

```
php artisan metamorph:make-model Post -R
```

This command will create three files:

- Eloquent model file

```
app/Models/Post.php

```

Is Laravel Eloquent model extends from `CrucialDigital\Metamorph\BaseModel.php` class. You are free to create your model with [Laravel syntax](https://laravel.com/docs/11.x/eloquent#generating-model-classes)and extends `CrucialDigital\Metamorph\BaseModel.php`. Consider implement `label()` and `search()` method responsible respectively for labeling form resource and define field on witch query with default search `term`

```
php artisan make:model Post
```

- Model repository file

```
app/Repositories/PostRepositories.php

```

Is the repository class responsible for creating the model query builder. You can also create repositories with artisan command

```
php artisan metamorph:make-repository PostRepository --model=Post
```

- Data model form file

```
database/models/post.json

```

The json file describes the form that handles the model with all its inputs. The json file structure looks like:

```
{
    "name": "Post form",
    "ref": "post",
    "entity": "post",
    "readOnly": true,
    "inputs": [
        {
            "field": "name",
            "type": "text",
            "name": "Name",
            "description": "Name of the role",
            "placeholder": "Enter the name of the role",
            "required": true,
            "readOnly": true
        },
        {
            "field": "created_by",
            "type": "resource",
            "entity": "user",
            "name": "Create by",
            "description": "Role create by",
            "placeholder": "Select user",
            "required": false,
            "hidden": true,
            "readOnly": true
        }
    ],
    "columns": [
        "name",
        "user.name"
    ]
}
```

where required fields are **entity** and **inputs**.

Each entry of **inputs** must have at least:

```
* field: The input field
* name: The label of the input
* type: The input type in list below
    * text
    * number
    * tel
    * email
    * date
    * datetime
    * radio
    * boolean
    * select
    * textarea
    * url
    * selectresource
    * resource
    * geopoint

```

For input of type select, **options** is required and is an array of object with **label** and **value**

For input of type **selectresource** and **resource**, **entity** filed is required. The entity must be unique for the model around your application

Other field are :

- required: boolean
- hidden: boolean
- readOnly: boolean
- rules: string (Laravel request rules pipe separated)
- description: string
- placeholder: string
- min: int
- max: int
- unique: boolean
- filters: [See table below](#model-entry-list-request-parameters)

> You are free to add any other field to the input that you can use in your frontend application

### Configure data model into metamorph config file

[](#configure-data-model-into-metamorph-config-file)

To configure how metamorph maps model with repository, data model form, controller and routes, you have to indicate in metamorph config file in models and repositories sections respectively the Eloquent model and model repository.

Example :

```
// config/metamorph.php
[
    ....
    'repositories' => [
         'post' => \App\Repositories\PostRepository::class,
         'user' => \App\Repositories\UserRepository::class
    ],
    'models' => [
         'post' => \App\Models\Post::class,
         'user' => \App\Models\User::class
    ]
    ...
]
```

### Run your data models

[](#run-your-data-models)

After creating your data models in .json files, you have to persist into your database with artisan command.

```
php artisan metamorph:models
```

This artisan command persists data models into the database. Every time you modify .json file in `database\models`, update data with this command. You can specify the name of the .json file with `--name` parameter

Consider configuring the mongodb database connection before.

### Make API requests

[](#make-api-requests)

Metamorph provides various endpoint de Create, Read, Update en Delete. Available endpoint are :

MethodsEndpointsDescriptionParametersPOSTapi/metamorph/exports/{entity}/{form}Export data with selected form`entity`: mapped model entity
 `form`: selected data formGET, HEADapi/metamorph/form-dataPOSTapi/metamorph/form-dataGET,HEADapi/metamorph/form-data/{form\_datum}PUT,PATCHapi/metamorph/form-data/{form\_datum}DELETEapi/metamorph/form-data/{form\_datum}POSTapi/metamorph/form-inputsGET,HEADapi/metamorph/form-inputs/{form\_input}PUT,PATCHapi/metamorph/form-inputs/{form\_input}DELETEapi/metamorph/form-inputs/{form\_input}POSTapi/metamorph/form/{entity}GET,HEADapi/metamorph/formsPOSTapi/metamorph/formsGET,HEADapi/metamorph/forms/{form}PUT,PATCHapi/metamorph/forms/{form}DELETEapi/metamorph/forms/{form}POSTapi/metamorph/many/searchPOSTapi/metamorph/master/{entity}Create model entry`entity`: mapped model entityGET,HEADapi/metamorph/master/{entity}/{id}Get model entry`entity`: mapped model entity
 `id`: model entity idPUT,PATCHapi/metamorph/master/{entity}/{id}Update model entry`entity`: mapped model entity
 `id`: model entity idDELETEapi/metamorph/master/{entity}/{id}Delete model entry`entity`: mapped model entity
 `id`: model entity idPATCHapi/metamorph/reject/form-data/{id}POSTapi/metamorph/resources/entitiesPOSTapi/metamorph/resources/entity/POSTapi/metamorph/search/{entity}Lists models entries[See table below](#model-entry-list-request-parameters)POSTapi/metamorph/validate/form-data/{id}
#### Model entry list request parameters

[](#model-entry-list-request-parameters)

ParameterDescriptionParameter typeValue typeDefault value`entity`mapped model entitystringurl part param`term`search term form route `search`stringquery param`paginate`whether paginate request or not *i.e: 0,1*string, intquery param*1*`per_page`number of element per page \_defaultintquery param*15*`order_by`order fieldstringquery param*created\_at*`order_direction`order direction of `order_by` *i.e : ASC, DESC*stringquery param*ASC*`randomize`whether result is randomize **Incompatible with paginate**int, stringquery param0`with_trash`whether result is with trashed entriesint, stringquery param0`only_trash`whether result is only trashed entriesint, stringquery param0`filters`filter criteria for the request
 *i.e: `[{field: 'title', operator: 'like', value: 'lorem', 'coordinator': 'and', 'group': 'or_mygroup' }...]`*
 *Available operator:*
 *=, !=, &lt;, &gt;, date, datebefore, dateafter, dateaftereq, datebeforeq, datenot, datebetween, datenotbetween, like, in, notin, between, notbetween, all, exists, elemMatch, size, regexp, type, mod, near, geoWithin, geoIntersects*
 **See [Mongodb query and projection operators documentation](https://www.mongodb.com/docs/rapid/reference/operator/query/) for more operator**object\[ \]query param*\[ \]*`search`Same as filtersobject\[ \]query param*\[ \]*> NOTE
> `field` : value of filters can be nested relation field `i.e: comments.user._id`
> `coordinator` : one of `and`, `or` to indicate using where(...) / orWhere(...)
> `group` : is used to group filter criteria into sub-query; the value must start with one of `and_` `or_`

Advanced
--------

[](#advanced)

### Global Middleware

[](#global-middleware)

To define global middleware for all metamorph routes, in metamorph config file, `config/metamorph.php`fill the `middlewares` array with your middlewares

```
//config/metamorph.php
...
'middlewares' => ['auth:sanctum', 'verified'],
...

```

> If you are using [Laravel Sanctum](https://laravel.com/docs/11.x/sanctum) for authentification, don't forget to add the middleware `auth:sanctum` to avoid trouble with [Metamorph authorisation system](#policies)

### Model Middleware

[](#model-middleware)

Beyond global middleware you can't define individual middleware for every model route and for each controller action in metamorph config file, `config/metamorph.php`fill the `model_middlewares` array with your middlewares

```
//config/metamorph.php
...
'model_middlewares' => [
    'post' => [
        'App\Http\Middleware\EnsureUserIsOwner::class' => '*', //Protect all CRUD action with the middleware for posts
        'isOwner' => ['destroy', 'update'] //Prevent non owner from deleting and updating posts
    ]
],
...

```

### Policies

[](#policies)

To authorize model controller action with police authorization, in metamorph config file, `config/metamorph.php`fill the `policies` array with the policy actions associate with your models

```
//config/metamorph.php
...
'policies' => [
    'post' => ['viewany', 'view', 'create', 'update', 'delete'],
    'user' => ['viewany', 'view', 'create', 'update', 'delete'],
    ...
 ],
...

```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Humbert DJAGLO](https://www.facebook.com/humbert.djaglo)
- [Mawaba BOTOSSI](https://www.facebook.com/tbotossi)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance57

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 56.9% 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 ~94 days

Recently: every ~135 days

Total

7

Last Release

207d ago

Major Versions

1.0.3 → 2.0.x-dev2025-02-08

2.0.x-dev → 3.0.02025-04-11

PHP version history (3 changes)1.0.0PHP ^8.0|^8.1|8.2

1.0.2PHP ^8.1|8.2

2.0.x-devPHP ^8.1|8.2|8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/853846e3f1b14a6cd5862c63045d07e087c01cbce3caf8bd48d1e64c0473568c?d=identicon)[crucialdigital](/maintainers/crucialdigital)

---

Top Contributors

[![Humbert1223](https://avatars.githubusercontent.com/u/68688359?v=4)](https://github.com/Humbert1223 "Humbert1223 (37 commits)")[![crucialdigital](https://avatars.githubusercontent.com/u/118361068?v=4)](https://github.com/crucialdigital "crucialdigital (28 commits)")

---

Tags

apicrudlaravelmongodbpackagerest-apiapilaravelrestdatabasemodelfiltermongodbfastcrudmetamorphcrucialdigital

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/crucialdigital-metamorph/health.svg)

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

###  Alternatives

[binaryk/laravel-restify

Laravel REST API helpers

651399.1k](/packages/binaryk-laravel-restify)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[bjerke/laravel-bread

A boilerplate package for BREAD operations through REST API in Laravel

115.2k](/packages/bjerke-laravel-bread)

PHPackages © 2026

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