Issues (56)

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

Labels
Severity
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\User;
6
use Illuminate\Console\Command;
7
8
class CreateUserCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'user:create {name? : The User name} {email? : The user email } {password? : The user password }';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Command description';
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
            User::create([
43
                'name'     => $this->argument('name') ? $this->argument('name') : $this->ask('User name?'),
44
                'email'    => $this->argument('email') ? $this->argument('email') : $this->ask('User email?'),
45
                'password' => $this->argument('password') ? $this->argument('password') : $this->ask('User password?'),
46
            ]);
47
        } 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...
48
            $this->error('error'.$e);
49
        }
50
51
        $this->info('User has been added to database succesfully');
52
    }
53
}
54