Archived
1
0
Fork 0

routes/console.php: Adding admin commands

This commit is contained in:
Henrik Hautakoski 2023-01-29 14:47:35 +01:00
parent f759542f68
commit a95e68e872

View file

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