改进 管理员控制台命令。
This commit is contained in:
parent
950cfe1c8e
commit
3956b3ddb2
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user