quimgc /
Tasks
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Console\Commands; |
||
| 4 | |||
| 5 | use App\User; |
||
| 6 | use Illuminate\Console\Command; |
||
| 7 | |||
| 8 | class DestroyUserCommand extends Command |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * The name and signature of the console command. |
||
| 12 | * |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $signature = 'user:destroy {id? : The user id}'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The console command description. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $description = 'This command destroy an existing user by id'; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Create a new command instance. |
||
| 26 | * |
||
| 27 | * @return void |
||
| 28 | */ |
||
| 29 | public function __construct() |
||
| 30 | { |
||
| 31 | parent::__construct(); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Execute the console command. |
||
| 36 | * |
||
| 37 | * @return mixed |
||
| 38 | */ |
||
| 39 | public function handle() |
||
| 40 | { |
||
| 41 | try { |
||
| 42 | $id = $this->argument('id') ? $this->argument('id') : $this->ask('User id?'); |
||
| 43 | $count = User::destroy($id); |
||
| 44 | } catch (Exception $e) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 45 | $this->error('error'.$e); |
||
| 46 | } |
||
| 47 | if ($count == 0) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 48 | $this->alert('User does not exist'); |
||
| 49 | } else { |
||
| 50 | $this->info('User has been deleted to database succesfully'); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 54 |