diff --git a/app/Console/Commands/Admin/All.php b/app/Console/Commands/Admin/All.php index 649027e..299350a 100644 --- a/app/Console/Commands/Admin/All.php +++ b/app/Console/Commands/Admin/All.php @@ -20,7 +20,7 @@ class All extends Command * * @var string */ - protected $description = '显示出所有 管理员。'; + protected $description = '显示出所有管理员。'; /** * Execute the console command. @@ -31,9 +31,10 @@ public function handle(): int { $admins = Admin::all(); - $this->table(['ID', '邮箱'], $admins->map(function ($admin) { + $this->table(['ID', '名称', '邮箱'], $admins->map(function ($admin) { return [ 'id' => $admin->id, + 'name' => $admin->name, 'email' => $admin->email, ]; })->toArray()); diff --git a/app/Console/Commands/Admin/Create.php b/app/Console/Commands/Admin/Create.php index 963687f..fc78692 100644 --- a/app/Console/Commands/Admin/Create.php +++ b/app/Console/Commands/Admin/Create.php @@ -20,7 +20,7 @@ class Create extends Command * * @var string */ - protected $description = '创建一个管理员账号'; + protected $description = '创建一个管理员账号。'; /** * Execute the console command. @@ -29,6 +29,9 @@ class Create extends Command */ public function handle(): int { + // 名称 + $name = $this->ask('请输入名称'); + // 邮箱 $email = $this->ask('请输入邮箱'); @@ -46,12 +49,13 @@ public function handle(): int // 创建管理员 $admin = (new Admin)->create([ + 'name' => $name, 'email' => $email, 'password' => bcrypt($password), ]); // 输出信息 - $this->info('管理员创建成功,ID为:'.$admin->id); + $this->info('管理员创建成功,ID 为: '.$admin->id.'。'); return CommandAlias::SUCCESS; } diff --git a/app/Console/Commands/Admin/Delete.php b/app/Console/Commands/Admin/Delete.php index dccb058..484ef23 100644 --- a/app/Console/Commands/Admin/Delete.php +++ b/app/Console/Commands/Admin/Delete.php @@ -20,7 +20,7 @@ class Delete extends Command * * @var string */ - protected $description = '删除一个管理员'; + protected $description = '删除一个管理员。'; /** * Execute the console command. @@ -30,7 +30,29 @@ class Delete extends Command public function handle(): int { // 获取管理员ID - $id = $this->ask('请输入管理员ID'); + $id = $this->ask('请输入管理员 ID'); + + // 搜索 + $admin = Admin::find($id); + if (is_null($admin)) { + $this->error('管理员不存在。'); + + return CommandAlias::FAILURE; + } + + // 输出信息 + $this->table(['ID', '名称', '邮箱'], [ + [ + 'id' => $admin->id, + 'name' => $admin->name, + 'email' => $admin->email, + ], + ]); + + // 确认 + if (! $this->confirm('确认删除管理员吗?')) { + return CommandAlias::FAILURE; + } // 删除管理员 Admin::destroy($id); diff --git a/app/Console/Commands/Admin/Reset.php b/app/Console/Commands/Admin/Reset.php index 04f5dfe..606714d 100644 --- a/app/Console/Commands/Admin/Reset.php +++ b/app/Console/Commands/Admin/Reset.php @@ -30,7 +30,7 @@ class Reset extends Command public function handle(): int { // 获取管理员ID - $id = $this->ask('请输入管理员ID'); + $id = $this->ask('请输入管理员 ID'); // 获取管理员 $admin = (new Admin)->find($id);