Issues (56)

app/Console/Commands/EditUserCommand.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Http\Requests\Traits\AsksForUsers;
6
use App\User;
7
use Illuminate\Console\Command;
8
9
class EditUserCommand extends Command
10
{
11
    use AsksForUsers;
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'user:edit {id? : The User id} {name? : The User name} {email? : The user email}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Edit an existing user.';
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
        //si ens passen l'id, l'agafem, perĂ² sino mostrem tots els id amb l'ajuda del Trait.
44
        $id = $this->argument('id') ? $this->argument('id') : $this->askForUsers();
45
46
        $user = User::findOrFail($id);
47
48
        try {
49
            $user->update([
50
                'name'        => $this->argument('name') ? $this->argument('name') : $this->ask('User name?'),
51
                'email'       => $this->argument('email') ? $this->argument('user_id') : $this->ask('User email?'),
52
            ]);
53
        } catch (Exception $e) {
0 ignored issues
show
The type App\Console\Commands\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
54
            $this->error('error'.$e);
55
        }
56
        $this->info('User has been edited succesfully');
57
    }
58
}
59