| @@ 8-53 (lines=46) @@ | ||
| 5 | use App\Task; |
|
| 6 | use Illuminate\Console\Command; |
|
| 7 | ||
| 8 | class ListTaskCommand extends Command |
|
| 9 | { |
|
| 10 | /** |
|
| 11 | * The name and signature of the console command. |
|
| 12 | * |
|
| 13 | * @var string |
|
| 14 | */ |
|
| 15 | protected $signature = 'task:list'; |
|
| 16 | ||
| 17 | /** |
|
| 18 | * The console command description. |
|
| 19 | * |
|
| 20 | * @var string |
|
| 21 | */ |
|
| 22 | protected $description = 'List all tasks 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 | ||
| 42 | //$headers = ['id','name','created_at','updated_at']; |
|
| 43 | ||
| 44 | try { |
|
| 45 | $tasks = Task::all()->toArray(); |
|
| 46 | $headers = array_keys($tasks[0]); |
|
| 47 | ||
| 48 | $this->table($headers, $tasks); |
|
| 49 | } catch (exception $e) { |
|
| 50 | $this->error('Error: '.$e); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 8-50 (lines=43) @@ | ||
| 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]); |
|
| 44 | ||
| 45 | $this->table($headers, $tasks); |
|
| 46 | } catch (exception $e) { |
|
| 47 | $this->error('Error: '.$e); |
|
| 48 | } |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||