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