Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php namespace Labkod\CMS\Console;
- use Illuminate\Console\Command;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Input\InputArgument;
- use App\User;
- class UserCreateCommand extends Command {
- /**
- * The console command name.
- *
- * @var string
- */
- protected $signature = 'cms:user:create
- {email? : E-mail of new user}
- {password? : Password of new user}
- {name? : Name of new user}
- {--A|admin : Set as admin role} ';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Create new user';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $email = $this->argument('email') ? $this->argument('email') : $this->ask("Email?");
- $password = $this->argument('password') ? $this->argument('password') : $this->secret('Password?');
- $name = $this->argument('name') ? $this->argument('name') : null;
- $is_admin = $this->option('admin') ? true : false;
- while(User::where("email", $email)->count() > 0){
- $this->error("This email is already in use. Please select another one.");
- $email = $this->ask("Email?");
- }
- $user = new User;
- $user->name = $name;
- $user->email = $email;
- $user->password = bcrypt($password);
- $user->is_admin = $is_admin;
- $user->save();
- $this->info(sprintf("User '%s' successfully created!", $email));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement