App\Console\Commands\CreateAdmin Class Reference
Inheritance diagram for App\Console\Commands\CreateAdmin:

Public Member Functions

 __construct ()
 Create a new command instance. More...
 
 handle ()
 Execute the console command. More...
 

Protected Attributes

 $signature = 'admin:create {--first_name=} {--last_name=} {--email=} {--username=} {--password=}'
 
 $description = 'Create an admin user via command line.'
 

Detailed Description

Definition at line 7 of file CreateAdmin.php.

Constructor & Destructor Documentation

App\Console\Commands\CreateAdmin::__construct ( )

Create a new command instance.

Returns
void

Definition at line 28 of file CreateAdmin.php.

29  {
30  parent::__construct();
31  }

Member Function Documentation

App\Console\Commands\CreateAdmin::handle ( )

Execute the console command.

Returns
mixed

Definition at line 38 of file CreateAdmin.php.

39  {
40 
41  $first_name = $this->option('first_name');
42  $last_name = $this->option('last_name');
43  $username = $this->option('username');
44  $email = $this->option('email');
45  $password = $this->option('password');
46 
47  if (($first_name=='') || ($last_name=='') || ($username=='') || ($email=='') || ($password=='')) {
48  $this->info('ERROR: All fields are required.');
49  } else {
50  $user = new \App\Models\User;
51  $user->first_name = $first_name;
52  $user->last_name = $last_name;
53  $user->username = $username;
54  $user->email = $email;
55  $user->permissions = '{"admin":1,"user":1,"superuser":1,"reports":1}';
56  $user->password = bcrypt($password);
57  $user->activated = 1;
58  if ($user->save()) {
59  $this->info('New user created');
60  $user->groups()->attach(1);
61  } else {
62  $this->info('Admin user was not created');
63  $errors = $user->getErrors();
64 
65  foreach ($errors->all() as $error) {
66  $this->info('ERROR:'. $error);
67  }
68 
69  }
70  }
71 
72  }

Member Data Documentation

App\Console\Commands\CreateAdmin::$description = 'Create an admin user via command line.'
protected

Definition at line 21 of file CreateAdmin.php.

App\Console\Commands\CreateAdmin::$signature = 'admin:create {--first_name=} {--last_name=} {--email=} {--username=} {--password=}'
protected

Definition at line 14 of file CreateAdmin.php.


The documentation for this class was generated from the following file: