diff --git a/app/Console/Commands/DemoteUser.php b/app/Console/Commands/DemoteUser.php new file mode 100644 index 0000000..2d2081e --- /dev/null +++ b/app/Console/Commands/DemoteUser.php @@ -0,0 +1,59 @@ +argument('username'))->first(); + if ($user === null) { + $this->error('No user with such username'); + return 1; + } + + if (!$user->is_admin) { + $this->info('@' . $user->name . ' is already an user.'); + return 0; + } + + $user->is_admin = false; + if ($user->save()) { + $this->info('@' . $user->name . ' is an user now.'); + } else { + $this->error('Something happened.'); + } + } +} diff --git a/app/Console/Commands/PromoteUser.php b/app/Console/Commands/PromoteUser.php new file mode 100644 index 0000000..8cfa452 --- /dev/null +++ b/app/Console/Commands/PromoteUser.php @@ -0,0 +1,59 @@ +argument('username'))->first(); + if ($user === null) { + $this->error('No user with such username'); + return 1; + } + + if ($user->is_admin) { + $this->info('@' . $user->name . ' is already an administrator.'); + return 0; + } + + $user->is_admin = true; + if ($user->save()) { + $this->info('@' . $user->name . ' is an administrator now.'); + } else { + $this->error('Something happened.'); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 622e774..da3f264 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -2,6 +2,8 @@ namespace App\Console; +use App\Console\Commands\DemoteUser; +use App\Console\Commands\PromoteUser; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; @@ -35,6 +37,8 @@ class Kernel extends ConsoleKernel */ protected function commands() { + $this->load(__DIR__.'/Commands'); + require base_path('routes/console.php'); } }