从php函数运行artisan命令

从php函数运行artisan命令

本文介绍了从php函数运行artisan命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从函数中运行 php artisanpassport:client --password .

我尝试了 Artisan :: call('passport:client'); Artisan :: command('passport:client'); ,但它返回了未定义的命令

I tryed Artisan::call('passport:client'); and Artisan::command('passport:client'); but it return undefined command

注意:我已经安装了laravel护照,并且该命令在终端上运行正常

推荐答案

我发现了它,在 PassportServiceProvider boot()方法中,有一项检查实际上是防止从 Artisan :: call 调用它.

I have found it, in boot() method of the PassportServiceProvider there is a check that essentially prevent it being called from Artisan::call.

//PassportServiceProvider.php at line 37:

if ($this->app->runningInConsole()) {

$this->commands([
    Console\InstallCommand::class,
    Console\ClientCommand::class,
    Console\KeysCommand::class,
]);
...
}

为了使其与一般的工匠命令兼容,我们可以自己注册这些命令.可能在 AuthServiceProvider 的启动方法中的某个位置.

to make it work with general artisan command, we can register these commands ourselves. somewhere within the boot method of AuthServiceProvider maybe.

public function boot() {
    $this->commands([
        Console\InstallCommand::class,
        Console\ClientCommand::class,
        Console\KeysCommand::class,
    ]);
}

现在我们可以调用 Artisan :: call('passport:install')或其他2个命令.

Now we can call Artisan::call('passport:install') or the other 2 commands.

这篇关于从php函数运行artisan命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 08:10