我想运行php artisan passport:client –password from function.
我尝试了Artisan :: call(‘passport:client’);和Artisan :: command(‘passport:client’);但它返回未定义的命令
注意:我已经安装了laravel passport,命令在终端上工作正常
解决方法:
我发现它,在PassportServiceProvider的boot()方法中有一个检查,基本上阻止它从Artisan :: call调用.
//PassportServiceProvider.php at line 37:
if ($this->app->runningInConsole()) {
$this->commands([
Console\InstallCommand::class,
Console\ClientCommand::class,
Console\KeysCommand::class,
]);
...
}
为了使它适用于一般工匠命令,我们可以自己注册这些命令.也许是AuthServiceProvider的启动方法中的某个地方.
public function boot() {
$this->commands([
Console\InstallCommand::class,
Console\ClientCommand::class,
Console\KeysCommand::class,
]);
}
现在我们可以调用Artisan :: call(‘passport:install’)或其他2个命令.