From 3956b3ddb24c8fc6a0826ffc74d06970f9fb3e39 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Mon, 20 Feb 2023 00:09:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E6=8E=A7=E5=88=B6=E5=8F=B0=E5=91=BD=E4=BB=A4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Console/Commands/Admin/All.php | 5 +++-- app/Console/Commands/Admin/Create.php | 8 ++++++-- app/Console/Commands/Admin/Delete.php | 26 ++++++++++++++++++++++++-- app/Console/Commands/Admin/Reset.php | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) 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);