hms5232/webman-factory
最新稳定版本:v0.2.0
Composer 安装命令:
composer require hms5232/webman-factory
包简介
Factory for webman framework.
README 文档
README
Factory for webman framework.
Installation
composer require --dev hms5232/webman-factory
You can remove the --dev flag as your need.
Usage
Like Laravel factory, but there are something different, and you need to do the following additional:
-
The factory class should extend
Hms5232\WebmanFactory\WebmanFactory:use Hms5232\WebmanFactory\WebmanFactory; class AdminFactory extends WebmanFactory { /** * Define the model's default state. * * @return array */ public function definition() { return [ 'name' => $this->faker->name(), 'email' => $this->faker->unique()->safeEmail(), ]; } }
-
The model class should use
Hms5232\WebmanFactory\HasFactoryinstead ofIlluminate\Database\Eloquent\Factories\HasFactory:- use Illuminate\Database\Eloquent\Factories\HasFactory; + use Hms5232\WebmanFactory\HasFactory; class Admin extends Model { use HasFactory; }
otherwise, you should specify the factory:
// app/model/Admin.php use database\factories\AdminFactory; /** * Create a new factory instance for the model. */ protected static function newFactory() { return AdminFactory::new(); }
Additional Features
Here are some additional features that can't be used before install related dependencies. Run the following command to see the details:
composer suggests hms5232/webman-factory
Command
We also provide make:factory to generate a new factory like Laravel:
php webman make:factory AdminFactory
The AdminFactory will be created in database/factories/AdminFactory.php and suppose the model is app/model/Admin.php by default. You can change these paths in config/plugin/hms5232/webman-factory/app.php.
License
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-25