routes/console.php: Adding admin commands
This commit is contained in:
parent
f759542f68
commit
a95e68e872
1 changed files with 52 additions and 0 deletions
|
|
@ -1,11 +1,13 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Admin;
|
||||
use App\Models\Card;
|
||||
use App\Models\Raid;
|
||||
use App\Models\Character;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
@ -181,3 +183,53 @@ Artisan::command('card:delete {id}', function ($id) {
|
|||
$this->warn(sprintf("Could not find card with id %s", $id));
|
||||
}
|
||||
})->purpose('Delete a card');
|
||||
|
||||
// Admin
|
||||
// --------------------------
|
||||
|
||||
Artisan::command('admin:add {username} {password}', function ($username, $password) {
|
||||
|
||||
Admin::create([
|
||||
'username' => $username,
|
||||
'password' => Hash::make($password)
|
||||
]);
|
||||
|
||||
$this->info("Created admin user");
|
||||
})->purpose('Add a admin user');
|
||||
|
||||
Artisan::command('admin:edit {id} {--username=} {--password=}', function ($id, $username=null, $password=null) {
|
||||
|
||||
$admin = Admin::find($id);
|
||||
if (!$admin) {
|
||||
$this->warn("Could not find admin.");
|
||||
return;
|
||||
}
|
||||
|
||||
if ($username) {
|
||||
$admin->username = $username;
|
||||
}
|
||||
if ($password) {
|
||||
$admin->password = Hash::make($password);
|
||||
}
|
||||
|
||||
$admin->save();
|
||||
|
||||
$this->info("Updated admin user");
|
||||
})->purpose('Edit a admin user');
|
||||
|
||||
Artisan::command('admin:delete {id}', function ($id) {
|
||||
$record = Admin::find($id);
|
||||
if ($record) {
|
||||
$record->delete();
|
||||
$this->info(sprintf("Admin #%s deleted", $id));
|
||||
} else {
|
||||
$this->warn(sprintf("Could not find admin with id %s", $id));
|
||||
}
|
||||
})->purpose('Delete a admin user');
|
||||
|
||||
Artisan::command('admin:list', function () {
|
||||
$cols = ['id', 'username', 'password', 'created_at', 'updated_at' ];
|
||||
$q = Admin::query();
|
||||
$data = $q->select($cols)->get()->makeVisible('password');
|
||||
$this->table($cols, $data);
|
||||
})->purpose('list admin users');
|
||||
Loading…
Add table
Add a link
Reference in a new issue