mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
add command user:generate
This commit is contained in:
53
app/Console/Commands/UserGenerate.php
Normal file
53
app/Console/Commands/UserGenerate.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use Database\Factories\UserFactory;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class UserGenerate extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'user:generate {--num=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Generate some user. options: --num=?';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$num = $this->option("num");
|
||||
$log = "num: $num";
|
||||
if (!$num) {
|
||||
$this->error("$log, no num!");
|
||||
}
|
||||
$size = 1000;
|
||||
$total = 0;
|
||||
do {
|
||||
if ($num < $size) {
|
||||
$size = $num;
|
||||
}
|
||||
if ($total + $size > $num) {
|
||||
$size = $num - $total;
|
||||
}
|
||||
User::factory($size)->create();
|
||||
$total += $size;
|
||||
$this->info("$log, success create $size !");
|
||||
} while($total < $num);
|
||||
$this->info("$log, total: $total, ALL DONE!");
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user