PHPackages                             meritum/model-factory - 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. meritum/model-factory

ActiveLibrary

meritum/model-factory
=====================

Model factory builder for the Meritum ecosystem

0.1.0(1mo ago)04↓75%MITPHPPHP ^8.4CI passing

Since Jul 16Pushed 1mo agoCompare

[ Source](https://github.com/MeritumIO/model-factory)[ Packagist](https://packagist.org/packages/meritum/model-factory)[ RSS](/packages/meritum-model-factory/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

meritum/model-factory
=====================

[](#meritummodel-factory)

Model factory builder for the Meritum ecosystem — defines Faker-backed attribute sets for `meritum/database` models and builds or persists them in tests and seeders. Each model gets its own factory `Definition`, registered via the `model.factory.definitions` kernel tag — the same pattern `meritum/cli` uses for commands — so any project can ship its own definitions and have them discovered automatically, with no central registry to maintain.

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

[](#requirements)

- PHP 8.4+
- `georgeff/kernel` ^1.10
- `meritum/database` ^1.3
- `fakerphp/faker` ^1.23

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

[](#installation)

```
composer require meritum/model-factory
```

Usage
-----

[](#usage)

### Defining a factory

[](#defining-a-factory)

Extend `Definition` once per model. It's constructed with a `Faker\Generator`, and returns the model's default attribute set:

```
use Faker\Generator;
use Meritum\ModelFactory\Definition;

final class PostDefinition extends Definition
{
    public function getModelClass(): string
    {
        return Post::class;
    }

    public function getDefinition(): array
    {
        return [
            'title' => $this->faker->sentence,
            'body'  => $this->faker->paragraph,
        ];
    }
}
```

### Registering the module

[](#registering-the-module)

Add `ModelFactoryModule` to your kernel. It requires a `DatabaseManagerInterface` to already be registered — the module doesn't build one itself, the same way `meritum/structured-logging` expects a `LoggerInterface` to already exist:

```
use Meritum\ModelFactory\ModelFactoryModule;
use Georgeff\Database\Contract\DatabaseManagerInterface;

$kernel->define(DatabaseManagerInterface::class, fn() => /* ... */);
$kernel->addModule(new ModelFactoryModule());
```

Each `Definition` subclass is registered like any other tagged service — the module doesn't scan for them, it resolves whatever's tagged:

```
use Faker\Generator;
use Psr\Container\ContainerInterface;
use Meritum\ModelFactory\FactoryOption;

$kernel->define(PostDefinition::class, fn(ContainerInterface $c) => new PostDefinition($c->get(Generator::class)))
       ->tag(FactoryOption::DefinitionTag->value);
```

### Building and persisting models

[](#building-and-persisting-models)

Resolve `ModelFactoryInterface` from the container and use `make()`, `create()`, or `collection()`:

```
use Meritum\ModelFactory\ModelFactoryInterface;

$factory = $kernel->getContainer()->get(ModelFactoryInterface::class);

// Build without persisting — attributes come from the Definition
$post = $factory->make(Post::class);

// Build with specific attributes overriding the Definition's defaults
$post = $factory->make(Post::class, ['title' => 'A specific title']);

// Build and persist
$post = $factory->create(Post::class);

// Build (or persist) several at once
$posts = $factory->collection(10, Post::class);           // persisted, keyed by primary key
$posts = $factory->collection(10, Post::class, [], false); // not persisted, keyed by index
```

`make()`/`create()`/`collection()` are generic over the model class — `$factory->make(Post::class)` is inferred as returning `Post`, not just the base `Model` type, so callers get proper static typing without needing to annotate anything themselves.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

46d ago

### Community

Maintainers

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

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/meritum-model-factory/health.svg)

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k6.1M793](/packages/sylius-sylius)[verbb/formie

The most user-friendly forms plugin for Craft.

102406.3k79](/packages/verbb-formie)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54691.6k28](/packages/solspace-craft-freeform)[elgg/elgg

Elgg is an award-winning social networking engine, delivering the building blocks that enable businesses, schools, universities and associations to create their own fully-featured social networks and applications.

1.7k17.3k100](/packages/elgg-elgg)[bowphp/framework

The bow PHP Framework

6018.0k14](/packages/bowphp-framework)[alleyinteractive/mantle-framework

A framework for powerful WordPress development

28376.6k2](/packages/alleyinteractive-mantle-framework)

PHPackages © 2026

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