Commit 86353fd0 authored by 梁俊杰's avatar 梁俊杰

支持自动生成填充数据文件功能,可方便一键生成全站假数据 php hyperf mm -s 15 -f -d 15代表你要每个表生成的数据 ...

支持自动生成填充数据文件功能,可方便一键生成全站假数据 php hyperf mm -s 15 -f -d  15代表你要每个表生成的数据  也可以做单表生成 php hyperf mm -s 150 -f products
parent 5f8c29e1
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
"hyperf/redis": "~1.1.0", "hyperf/redis": "~1.1.0",
"hyperf/guzzle": "~1.1.0", "hyperf/guzzle": "~1.1.0",
"hyperf/config": "~1.1.0", "hyperf/config": "~1.1.0",
"hyperf/service-governance": "~1.1.0" "hyperf/service-governance": "~1.1.0",
"fzaninotto/faker": "^1.9"
}, },
"minimum-stability": "dev", "minimum-stability": "dev",
"autoload": { "autoload": {
......
This diff is collapsed.
<?php
declare(strict_types=1);
use Hyperf\Database\Seeders\Seeder;
use Hyperf\DbConnection\Db;
class DataBaseSeeder extends Seeder
{
/**
* Run the database seeds.
* @return void
*/
public function run()
{
/**
* var $seeders 可执行的seeder填充类
**/
$seeders = [
];
Db::statement('SET FOREIGN_KEY_CHECKS = 0');
foreach($seeders as $item){
require BASE_PATH . "/seeders/seeders/" . \Hyperf\Utils\Str::snake(str_replace("::class", "", $item)) . ".php";
$instance = new $item;
$instance->run();
}
Db::statement('SET FOREIGN_KEY_CHECKS = 1');
}
}
...@@ -32,6 +32,8 @@ class %ClassName% extends Migration ...@@ -32,6 +32,8 @@ class %ClassName% extends Migration
*/ */
public function down(): void public function down(): void
{ {
Schema::disableForeignKeyConstraints();
Schema::dropIfExists('%tablename%'); Schema::dropIfExists('%tablename%');
Schema::enableForeignKeyConstraints();
} }
} }
<?php
declare(strict_types=1);
use App\Model\%modelClass%;%otherModel%
use Faker\Factory;
use Hyperf\Database\Seeders\Seeder;
use Hyperf\DbConnection\Db;
class %className% extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$faker = Factory::create('zh-CN');
%modelClass%::truncate();
$n = %generateCount%;
for ($i = 0; $i < $n; $i++) {
$instance = %modelClass%::create([
%fields%
]);
%otherProcess%
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment