Переглянути джерело

Update UserCreate command, closes #2581

Daniel Supernault 4 роки тому
батько
коміт
b2b8c9f99c
1 змінених файлів з 21 додано та 1 видалено
  1. 21 1
      app/Console/Commands/UserCreate.php

+ 21 - 1
app/Console/Commands/UserCreate.php

@@ -12,7 +12,7 @@ class UserCreate extends Command
      *
      * @var string
      */
-    protected $signature = 'user:create';
+    protected $signature = 'user:create {--name=} {--username=} {--email=} {--password=} {--is_admin=0} {--confirm_email=0}';
 
     /**
      * The console command description.
@@ -40,6 +40,26 @@ class UserCreate extends Command
     {
         $this->info('Creating a new user...');
 
+        $o = $this->options();
+
+        if( $o['name'] &&
+            $o['username'] &&
+            $o['email'] &&
+            $o['password']
+        ) {
+            $user = new User;
+            $user->username = $o['username'];
+            $user->name = $o['name'];
+            $user->email = $o['email'];
+            $user->password = bcrypt($o['password']);
+            $user->is_admin = (bool) $o['is_admin'];
+            $user->email_verified_at = (bool) $o['confirm_email'] ? now() : null;
+            $user->save();
+
+            $this->info('Successfully created user!');
+            return;
+        }
+
         $name = $this->ask('Name');
 
         $username = $this->ask('Username');