eric98 /
Tasks
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Console\Commands; |
||
| 4 | |||
| 5 | use App\Task; |
||
| 6 | use App\User; |
||
| 7 | use Illuminate\Console\Command; |
||
| 8 | use Mockery\Exception; |
||
| 9 | |||
| 10 | class ListTasksCommand extends Command |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * The name and signature of the console command. |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $signature = 'task:list'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The console command description. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $description = 'List all tasks'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Create a new command instance. |
||
| 28 | * |
||
| 29 | * @return void |
||
| 30 | */ |
||
| 31 | public function __construct() |
||
| 32 | { |
||
| 33 | parent::__construct(); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Execute the console command. |
||
| 38 | * |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | public function handle() |
||
| 42 | { |
||
| 43 | try { |
||
| 44 | $tasks = Task::all(); |
||
| 45 | |||
| 46 | $headers = ['id', 'Name', 'Completed', 'User id', 'User Name']; |
||
| 47 | $fields = []; |
||
| 48 | foreach ($tasks as $task) { |
||
| 49 | $fields[] = [ |
||
| 50 | 'id:' => $task->id, |
||
| 51 | 'Name:' => $task->name, |
||
| 52 | 'Completed:' => $task->completed ? 'Yes' : 'No', |
||
| 53 | 'User id:' => $task->user_id, |
||
| 54 | 'User name:' => User::findOrFail($task->user_id)->name, |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 55 | ]; |
||
| 56 | } |
||
| 57 | } catch (Exception $e) { |
||
| 58 | $this->error('Error'); |
||
| 59 | } |
||
| 60 | $this->table($headers, $fields); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
|
|||
| 61 | } |
||
| 62 | } |
||
| 63 |