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