管理员 部分
This commit is contained in:
parent
ac48b764a4
commit
77508d0fb9
43
app/Console/Commands/Admin/All.php
Normal file
43
app/Console/Commands/Admin/All.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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.
|
41
app/Console/Commands/Admin/Delete.php
Normal file
41
app/Console/Commands/Admin/Delete.php
Normal 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;
|
||||
}
|
||||
}
|
55
app/Console/Commands/Admin/Reset.php
Normal file
55
app/Console/Commands/Admin/Reset.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user