mirror of
https://github.com/axeloz/filesharing.git
synced 2025-05-06 10:03:55 +02:00
Delete user command
This commit is contained in:
parent
f48504394f
commit
8c8746b8c9
1 changed files with 45 additions and 0 deletions
45
app/Console/Commands/DeleteUser.php
Normal file
45
app/Console/Commands/DeleteUser.php
Normal file
|
@ -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').'"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue