cable8mm / xeed
Xeed旨在根据现有数据库表中的数据为Laravel生成新模型、种子、数据库种子、工厂和迁移文件。
Requires
- php: ^8.0.2
- cable8mm/array-flatten: ^1.0
- doctrine/inflector: ^2.0
- league/flysystem: ^3.0
- symfony/console: ^6.0|^7.0
- vlucas/phpdotenv: ^5.0
Requires (Dev)
- fakerphp/faker: ^1.23
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0|^7.0|^8.0
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
Suggests
- php: `symfony/console` need `^8.0.2` over.
- cable8mm/array-flatten: To enable more efficient database schema mapping.
- doctrine/inflector: To get a Laravel Model name from a table name.
- symfony/console: Console framework to be used.
- vlucas/phpdotenv: To read `.env` configuration.
README
Xeed旨在根据现有数据库表中的数据为Laravel生成新模型、种子、数据库种子、工厂和迁移文件。
提示
它既可以作为Laravel的php artisan xeed:*
命令,也可以作为独立应用程序的bin/console *
命令,提供100%相同的功能。因此,您可以在自己的Laravel项目中或作为独立应用程序使用它。
我们在网站上提供了API文档。更多信息,请访问https://www.palgle.com/xeed/ ❤️
特性
- 支持数据库测试
- 为Laravel生成模型
- 为Laravel生成种子文件
- 为Laravel生成数据库种子文件
- 为Laravel生成工厂
- 为Laravel生成迁移
- 为Laravel生成belongsTo和hasMany关系函数
- 支持Laravel多列和保留列
- 支持Laravel集成
- 支持MySQL、SQLite和PostgreSQL
支持 & 测试
注意
PostgreSQL支持处于测试阶段。如果您遇到任何问题,请通过GitHub问题报告。
预览
Laravel
独立
安装
composer require cable8mm/xeed --dev
# For Laravel
composer create-project cable8mm/xeed
# For Standalone
重要
编辑.env
文件以配置您自己的数据库。您需要时可以手动将.env.example
复制到.env
。
使用方法
生成模型
php artisan xeed:models # Generate all models from database in `app/Models` folder php artisan xeed:models -f -t xeeds # Force to generate a model from `xeeds` table in `app/Models` folder
bin/console models # Generate all models from database in `dist/app/Models` folder bin/console models -f -t xeeds # Force to generate a model from `xeeds` table in `app/Models` folder
生成种子
php artisan xeed:seeders # Generate all seeds from database in `database/seeders` folder php artisan xeed:seeders -f -t xeeds # Force to generate a seeder from `xeeds` table in `database/seeders` folder
bin/console seeders # Generate all seeds from database in `dist/database/seeders` folder bin/console seeders -f -t xeeds # Force to generate a seeder from `xeeds` table in `dist/database/seeders` folder
生成Faker种子
Faker种子在没有使用factory()
方法的情况下使用来生成种子。此命令的创建是为了解决问题#61,提供其用途的见解。
php artisan xeed:faker-seeders # Generate all seeds from database in `database/seeders` folder php artisan xeed:faker-seeders -f -t xeeds # Force to generate a seeder from `xeeds` table in `database/seeders` folder
bin/console faker-seeders # Generate all seeds from database in `dist/database/seeders` folder bin/console faker-seeders -f -t xeeds # Force to generate a seeder from `xeeds` table in `dist/database/seeders` folder
生成DatabaseSeeder
php artisan xeed:database
# Generate a database seed from database in `database/seeders` folder
bin/console database
# Generate a database seed from database in `dist/database/seeders` folder
生成工厂
php artisan xeed:factories # Generate all factories from database in `database/factories' folder php artisan xeed:factories -f -t xeeds # Force to generate a factory from `xeeds` table in `database/factories' folder
bin/console factories # Generate all factories from database in `dist/database/factories' folder bin/console factories -f -t xeeds # Force to generate a factory from `xeeds` table in `database/factories' folder
生成迁移
php artisan xeed:migrations # Generate all migrations from database in `database/migrations' folder php artisan xeed:migrations -f -t xeeds # Force to generate a migration from `xeeds` table in `database/migrations' folder
bin/console migrations # Generate all migrations from database in `dist/database/migrations' folder bin/console migrations -f -t xeeds # Force to generate a migration from `xeeds` table in `database/migrations' folder
生成的文件存储在与您的Laravel项目相同的文件夹中。请检查dist
文件夹。
生成关系
此命令只能在存在use HasFactory;
的模型中使用,所有关系都将放置在其后。
php artisan xeed:relations # Add the relation function to all models from database in `app/Models` folder php artisan xeed:relations -m # Runs xeed:models before running xeed:relations. Add -f to force to generate
bin/console relations # Add the relation function to all models from database in `dist/app/Models` folder bin/console relations -m # Runs xeed:models before running xeed:relations. Add -f to force to generate
生成的关联使用laravels约定命名。一些名称可能重复
有用的命令
如果您要自己测试此包,请使用以下命令清理生成的文件。
php artisan xeed:clean # Clean generated files, seeders, models, factories and migration files. #=> Refer the below Please select directory for you to want to clean. [0] seeder [1] model [2] factory [3] migration [4] all [5] exit
bin/console clean # Clean generated files, seeders, models, factories and migration files. #=> Refer the below Please select directory for you to want to clean. [0] seeder [1] model [2] factory [3] migration [4] all [5] exit
格式化
composer lint # Modify all files to comply with the PSR-12. composer inspect # Inspect all files to ensure compliance with PSR-12.
测试
它使用内置的SQLite数据库,而不是您自己的数据库。它永远不会损害您的数据。您不需要担心这一点。
composer testpack
# All tests with Laravel artisan commands
composer test # All tests without Laravel artisan commands
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
贡献
有关详细信息,请参阅CONTRIBUTING。
以下内容可以帮助您贡献。
Xeed内置了SQLite数据库,允许您在不需要自己的数据库的情况下轻松贡献。只需为测试目的创建一个新文件并使用它。
touch database/database.sqlite
# Create a new empty file for SQLite database
然后,
composer test # Run tests
数据库种子
对于迁移和工厂,当您需要为所有数据库字段类型执行测试时,请使用以下命令。
php artisan xeed # Import an 'xeeds' Table into the Database php artisan xeed drop # Drop the 'xeeds' Table from the Database
bin/console xeed # Import an 'xeeds' Table into the Database bin/console xeed drop # Drop the 'xeeds' Table from the Database
通过引用以下位置database/*.sql
使用迁移文件来引用所有数据库字段类型,这些文件保存在指定的文件夹中。
使用testorchestral/testbench
您可以使用testorchestral/testbench
来执行测试。当运行Laravel命令时,生成的文件将保存在vendor/orchestra/testbench-core/laravel/database
文件夹中。
鸣谢
许可证
Xeed 项目是开源软件,遵循 MIT 许可协议。