laravel 得到如下错误:- [Symfony\Component\Console\Exception\RuntimeException] 参数太多

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36417682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:32:05  来源:igfitidea点击:

getting error like:- [Symfony\Component\Console\Exception\RuntimeException] Too many arguments

laravellaravel-5.2

提问by Ketan Akbari

This is my UserCreateCommand.php file when command:- php artisan user-create username password getting error like:- [Symfony\Component\Console\Exception\RuntimeException] Too many arguments.

这是我的 UserCreateCommand.php 文件,当命令:- php artisan 用户创建用户名密码时出现错误,例如:- [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');
}
}

回答by Ketan Akbari

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');


}

working fine when used command:- php artisan user-create

使用命令时工作正常:- php artisan user-create