Skip to content

Instantly share code, notes, and snippets.

@ZhangYiJiang
Created May 5, 2016 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhangYiJiang/f47bc46ca62edaa5e6c8c2ea6d3b54a0 to your computer and use it in GitHub Desktop.
Save ZhangYiJiang/f47bc46ca62edaa5e6c8c2ea6d3b54a0 to your computer and use it in GitHub Desktop.
Add user command for Laravel
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\User;
class AddUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:add {email}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates a 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');
if ($this->confirm('Let system generate password for you?')) {
$password = str_random(16);
$this->info("Your password: $password");
} else {
$password = $this->secret('Please enter your new password');
}
$password = bcrypt($password);
User::create(compact('email', 'password'));
}
}
@amosmos
Copy link

amosmos commented Sep 26, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment