I want to run php artisan passport:client --password from function.
I tryed Artisan::call('passport:client'); and Artisan::command('passport:client'); but it return undefined command
Note: I have alredy install laravel passport and the command is working fine from the terminal
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,
]);
...
}
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,
    ]);
}
Now we can call Artisan::call('passport:install') or the other 2 commands.
From Laravel Docs
Route::get('/foo', function () {
$exitCode = Artisan::call('email:send', [
    'user' => 1, '--queue' => 'default'
]);
//
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With