PHPackages                             yunbuye/thinkphp-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. [Database &amp; ORM](/categories/database)
4. /
5. yunbuye/thinkphp-model-factory

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

yunbuye/thinkphp-model-factory
==============================

ThinkPHP 模型工厂

0.8.3(6y ago)1661[1 PRs](https://github.com/yunbuye/thinkphp-model-factory/pulls)MITPHPPHP &gt;=7.1.3

Since Dec 31Pushed 3y ago2 watchersCompare

[ Source](https://github.com/yunbuye/thinkphp-model-factory)[ Packagist](https://packagist.org/packages/yunbuye/thinkphp-model-factory)[ Docs](http://github.com/yunbuye/thinkphp-model-factory)[ RSS](/packages/yunbuye-thinkphp-model-factory/feed)WikiDiscussions master Synced today

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

yunbuye/thinkphp-model-factory
==============================

[](#yunbuyethinkphp-model-factory)

thinkphp 的模型工厂
--------------

[](#thinkphp-的模型工厂)

方便的批量生成模型的模拟数据

说明
--

[](#说明)

此为[laravel的模型工厂](https://learnku.com/docs/laravel/6.x/database-testing/5185#writing-factories)的thinkphp的适配版，大部分功能都可用（需要手动创建工厂文件，定义数据库连接不可用）

使用
--

[](#使用)

1. 安装

```
composer require yunbuye/thinkphp-model-factory
```

1. 建立目录
    在根目录建立 "./database/factories" 工厂目录
2. 使用

    1. 定义工厂，在工厂目录 新建和编写工厂 ```
        use Faker\Generator as Faker;

        $factory->define(App\User::class, function (Faker $faker) {
            return [
                'name' => $faker->name,
                'email' => $faker->unique()->safeEmail,
                'email_verified_at' => now(),
                'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
                'remember_token' => Str::random(10),
            ];
        });
        ```
    2. 在模型中使用工厂 ```
        public function testDatabase()
        {
            $user = factory(App\User::class)->make();

            // 在测试中使用模型...
        }
        ```
3. 语言
    默认中文zh\_CN
    可以添加配置 app.faker\_locale 到配置文件进行定义

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

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

Every ~3 days

Total

4

Last Release

2313d ago

### Community

Maintainers

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

---

Top Contributors

[![xwpd](https://avatars.githubusercontent.com/u/17465049?v=4)](https://github.com/xwpd "xwpd (10 commits)")

---

Tags

factorymodelthinkphp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[spatie/laravel-translatable

A trait to make an Eloquent model hold translations

2.4k23.0M412](/packages/spatie-laravel-translatable)[spatie/eloquent-sortable

Sortable behaviour for eloquent models

1.5k22.9M266](/packages/spatie-eloquent-sortable)[nhzex/think-phinx

Phinx integration for thinkphp

243.1k](/packages/nhzex-think-phinx)

PHPackages © 2026

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