Passport: Artisan::call not seeing passport commands even it work from ssh command line

Created on 6 Mar 2018  ·  5Comments  ·  Source: laravel/passport

Artisan::call not seeing passport commands even it work from ssh command line

i have new laravel 5.6 project with passport installed
if i run php artisan you can see passport command appear and work

but if its called from Artisan::call within route like this willget error
There are no commands defined in the "passport" namespace.

Route::any('/passportprepeare', function () {
    Artisan::call('passport:install --force', ['--force' => true]);
});

even the db migrate if called from command line will include passport tables if called through Artisan::call passport tables not migrated
Artisan::call('migrate:refresh', ['--force' => true]);

Route::any('/migrateDB', function () {
 Artisan::call('migrate:refresh', ['--force' => true]);
});

Most helpful comment

Better Option

You can make everything work fine if you configure you app/Providers/AppServiceProvider.php file like below

use Laravel\Passport\Console\ClientCommand;
use Laravel\Passport\Console\InstallCommand;
use Laravel\Passport\Console\KeysCommand;

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

The Passport install command should work perfectly.

All 5 comments

if u need commands need to be registered in boot provider as laravel code check
if ($this->app->runningInConsole()) {
}

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

if u need migration
Artisan::call('migrate', [
'--path' => 'vendor/laravel/passport/database/migrations',
'--force' => true,

]);

This code works with no error for installing passport on shared hosting

shell_exec('php ../artisan passport:install');

shell_exec('php ../artisan passport:install');

It worked for me too, thanks

Better Option

You can make everything work fine if you configure you app/Providers/AppServiceProvider.php file like below

use Laravel\Passport\Console\ClientCommand;
use Laravel\Passport\Console\InstallCommand;
use Laravel\Passport\Console\KeysCommand;

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

The Passport install command should work perfectly.

This code works with no error for installing passport on shared hosting

shell_exec('php ../artisan passport:install');

where the code is placed?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

duccanh0022 picture duccanh0022  ·  3Comments

brryfrmnn picture brryfrmnn  ·  3Comments

andcl picture andcl  ·  3Comments

soubhikchatterjee picture soubhikchatterjee  ·  4Comments

MarkVilludo picture MarkVilludo  ·  3Comments