smousss / laravel-factorize
使用 GPT-4 轻松为您的所有模型生成 Laravel 工厂!
0.1.3
2023-04-20 09:39 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
README
神奇地添加缺失的模型工厂
Smousss 会生成缺失的模型工厂,帮助您轻松创建假数据种子和编写测试。这对于继承旧代码库的开发者来说是一个梦想成真。
namespace Database\Factories; use … class ThreadFactory extends Factory { public function definition() { return [ 'title' => fake()->sentence(), 'slug' => fake()->slug(), 'content' => fake()->paragraph(), ]; } public function withUser(): static { return $this->state(function () { return [ 'user_id' => User::factory(), ]; }); } … }
安装
使用 Composer 安装包
composer require smousss/laravel-factorize
发布配置文件
php artisan vendor:publish --tag=factorize-config
使用方法
- 首先,在 smousss.com 上生成一个密钥。
- 将其添加到您的
SMOUSSS_SECRET_KEY
环境变量中。 - 然后,为您的 Post 模型创建一个工厂:
php artisan smousss:factorize App\\Models\\Post
。或者为多个模型:php artisan smousss:factorize App\\Models\\Post App\\Models\\Comment
致谢
Factorize for Laravel 是由 Benjamin Crozat 为 Smousss (Twitter) 开发的。