管理员 部分

This commit is contained in:
iVampireSP.com 2022-11-17 19:52:23 +08:00
parent ac48b764a4
commit 77508d0fb9
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
4 changed files with 142 additions and 3 deletions

View File

@ -0,0 +1,43 @@
<?php
namespace App\Console\Commands\Admin;
use App\Models\Admin;
use Illuminate\Console\Command;
class All extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'admin:list';
/**
* The console command description.
*
* @var string
*/
protected $description = '显示出所有 管理员。';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$admins = Admin::all();
$this->table(['ID', '邮箱'], $admins->map(function ($admin) {
return [
'id' => $admin->id,
'email' => $admin->email,
];
})->toArray());
return Command::SUCCESS;
}
}

View File

@ -1,19 +1,19 @@
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\Admin;
use App\Models\Admin;
use Illuminate\Console\Command;
use Symfony\Component\Console\Command\Command as CommandAlias;
class CreateAdmin extends Command
class Create extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'create:admin';
protected $signature = 'admin:create';
/**
* The console command description.

View File

@ -0,0 +1,41 @@
<?php
namespace App\Console\Commands\Admin;
use App\Models\Admin;
use Illuminate\Console\Command;
class Delete extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'admin:delete';
/**
* The console command description.
*
* @var string
*/
protected $description = '删除一个管理员';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
// 获取管理员ID
$id = $this->ask('请输入管理员ID');
// 删除管理员
Admin::destroy($id);
// 输出信息
$this->info('管理员删除成功。');
return Command::SUCCESS;
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace App\Console\Commands\Admin;
use App\Models\Admin;
use Illuminate\Console\Command;
class Reset extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'admin:reset';
/**
* The console command description.
*
* @var string
*/
protected $description = '重置一个管理员的密码';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
// 获取管理员ID
$id = $this->ask('请输入管理员ID');
// 获取管理员
$admin = Admin::find($id);
// 验证管理员
if (is_null($admin)) {
$this->error('管理员不存在。');
return Command::FAILURE;
}
// 密码
$password = $this->secret('请输入密码');
$admin->password = bcrypt($password);
$admin->save();
// 输出信息
$this->info('管理员密码重置成功。');
return Command::SUCCESS;
}
}