这是我的UserCreateCommand.php文件,当命令: - php artisan user-create username password getting error like: - [Symfony \ Component \ Console \ Exception \ RuntimeException]参数太多。
class UserCreateCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user-create';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create user with password imediately';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$username=$this->argument('username');
$password=$this->argument('password');
$user= new UserDemo();
$user->username=$username;
$user->password=Hash::make($password);
$user->save();
$this->info('user has been cretaed');
}
}
答案 0 :(得分:1)
public function handle()
{
//
$username=$this->ask('username');
$password=$this->secret('password');
$user= new UserDemo();
$user->username=$username;
$user->password=Hash::make($password);
$user->save();
$this->info('user has been cretaed');
}
使用命令时工作正常: - php artisan user-create