quimgc /
Tasks
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Console\Commands; |
||
| 4 | |||
| 5 | use App\User; |
||
| 6 | use Illuminate\Console\Command; |
||
| 7 | |||
| 8 | class ListUserCommand extends Command |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * The name and signature of the console command. |
||
| 12 | * |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $signature = 'user:list'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The console command description. |
||
| 19 | * |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $description = 'List all users with a table format.'; |
||
| 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 | $tasks = User::all()->toArray(); |
||
| 43 | $headers = array_keys($tasks[0]); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 44 | |||
| 45 | $this->table($headers, $tasks); |
||
| 46 | } catch (exception $e) { |
||
|
0 ignored issues
–
show
|
|||
| 47 | $this->error('Error: '.$e); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | } |
||
| 51 |