改进 管理员控制台命令。

This commit is contained in:
iVampireSP.com 2023-02-20 00:09:53 +08:00
parent 950cfe1c8e
commit 3956b3ddb2
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
4 changed files with 34 additions and 7 deletions

View File

@ -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());

View File

@ -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;
}

View File

@ -20,7 +20,7 @@ class Delete extends Command
*
* @var string
*/
protected $description = '删除一个管理员';
protected $description = '删除一个管理员';
/**
* Execute the console command.
@ -32,6 +32,28 @@ public function handle(): int
// 获取管理员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);