PHPackages                             mpociot/laravel-test-factory-helper - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. mpociot/laravel-test-factory-helper

ActiveLibrary[Testing &amp; Quality](/categories/testing)

mpociot/laravel-test-factory-helper
===================================

Generate Laravel test factories from your existing models

v2.1.0(6y ago)933635.2k—0%86[7 issues](https://github.com/mpociot/laravel-test-factory-helper/issues)[7 PRs](https://github.com/mpociot/laravel-test-factory-helper/pulls)2MITPHPPHP ^7.2.5

Since Mar 26Pushed 2y ago9 watchersCompare

[ Source](https://github.com/mpociot/laravel-test-factory-helper)[ Packagist](https://packagist.org/packages/mpociot/laravel-test-factory-helper)[ RSS](/packages/mpociot-laravel-test-factory-helper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (21)Used By (2)

Laravel Test Factory Generator
------------------------------

[](#laravel-test-factory-generator)

`php artisan generate:model-factory`

This package will generate [factories](https://laravel.com/docs/master/database-testing#writing-factories) from your existing models so you can get started with testing your Laravel application more quickly.

### Example output

[](#example-output)

#### Migration and Model

[](#migration-and-model)

```
Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('username');
    $table->string('email')->unique();
    $table->string('password', 60);
    $table->integer('company_id');
    $table->rememberToken();
    $table->timestamps();
});

class User extends Model {
    public function company()
    {
        return $this->belongsTo(Company::class);
    }
}
```

#### Factory Result

[](#factory-result)

```
$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'username' => $faker->userName,
        'email' => $faker->safeEmail,
        'password' => bcrypt($faker->password),
        'company_id' => factory(App\Company::class),
        'remember_token' => Str::random(10),
    ];
});
```

### Install

[](#install)

Require this package with composer using the following command:

```
composer require --dev mpociot/laravel-test-factory-helper
```

### Usage

[](#usage)

To generate multiple factories at once, run the artisan command:

`php artisan generate:model-factory`

This command will find all models within your application and create test factories. By default, this will not overwrite any existing model factories. You can *force* overwriting existing model factories by using the `--force` option.

To generate a factory for specific model or models, run the artisan command:

`php artisan generate:model-factory User Team`

By default, this command will search under the `app` folder for models. If your models are within a different folder, for example `app/Models`, you can specify this using `--dir` option. In this case, run the artisan command:

`php artisan generate:model-factory --dir app/Models -- User Team`

### License

[](#license)

The Laravel Test Factory Helper is free software licensed under the MIT license.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity59

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~75 days

Recently: every ~46 days

Total

20

Last Release

2262d ago

Major Versions

0.5.0 → 1.0.02019-06-18

v1.3 → v2.0.02020-01-01

PHP version history (5 changes)0.1PHP &gt;=5.4.0

0.3.0PHP &gt;=5.6.0

1.0.0PHP &gt;=7.0

v2.0.0PHP ^7.2

v2.1.0PHP ^7.2.5

### Community

Maintainers

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

---

Top Contributors

[![jasonmccreary](https://avatars.githubusercontent.com/u/161071?v=4)](https://github.com/jasonmccreary "jasonmccreary (25 commits)")[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (12 commits)")[![skeets23](https://avatars.githubusercontent.com/u/13846271?v=4)](https://github.com/skeets23 "skeets23 (11 commits)")[![jijoel](https://avatars.githubusercontent.com/u/3487641?v=4)](https://github.com/jijoel "jijoel (2 commits)")[![edmandiesamonte](https://avatars.githubusercontent.com/u/11081512?v=4)](https://github.com/edmandiesamonte "edmandiesamonte (2 commits)")[![dontfreakout](https://avatars.githubusercontent.com/u/1829574?v=4)](https://github.com/dontfreakout "dontfreakout (1 commits)")[![SvenSlijkoord](https://avatars.githubusercontent.com/u/11380389?v=4)](https://github.com/SvenSlijkoord "SvenSlijkoord (1 commits)")[![dweinerATL](https://avatars.githubusercontent.com/u/5572940?v=4)](https://github.com/dweinerATL "dweinerATL (1 commits)")[![ilvsx](https://avatars.githubusercontent.com/u/5467343?v=4)](https://github.com/ilvsx "ilvsx (1 commits)")[![Jeroen-G](https://avatars.githubusercontent.com/u/1116853?v=4)](https://github.com/Jeroen-G "Jeroen-G (1 commits)")[![Oussama-Tn](https://avatars.githubusercontent.com/u/787632?v=4)](https://github.com/Oussama-Tn "Oussama-Tn (1 commits)")

---

Tags

laravellaravel-5-packagelaravelfactorytests

### Embed Badge

![Health badge](/badges/mpociot-laravel-test-factory-helper/health.svg)

```
[![Health](https://phpackages.com/badges/mpociot-laravel-test-factory-helper/health.svg)](https://phpackages.com/packages/mpociot-laravel-test-factory-helper)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/ui

Laravel UI utilities and presets.

2.7k134.9M601](/packages/laravel-ui)[thedoctor0/laravel-factory-generator

Automatically generate Laravel factories for your models.

214997.4k1](/packages/thedoctor0-laravel-factory-generator)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)

PHPackages © 2026

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