Skip to content

Commit

Permalink
Delete user command
Browse files Browse the repository at this point in the history
  • Loading branch information
axeloz committed Jul 5, 2023
1 parent f485043 commit 8c8746b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/Console/Commands/DeleteUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Console\Commands;

use App\Models\User;
use Exception;
use Illuminate\Console\Command;

class DeleteUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fs:user:delete {login}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
public function handle()
{
$user = User::where('username', $this->argument('login'))->first();
if (empty($user)) {
$this->error('No such user "'.$this->argument('login').'"');
}
else {
try {
$user->delete();
$this->info('User "'.$this->argument('login').'" has been deleted');
}
catch (Exception $e) {
$this->error('Could not delete user "'.$this->argument('login').'"');
}
}

}
}

0 comments on commit 8c8746b

Please sign in to comment.