stackprogramer's avatar

Why The command "passport:keys" does not exist in php artisan::call

I installed successfully passport package, it works correctly in Laravel controller i need passport key generate again but i have error. How can solve this problem? I don't have access shell exec I want to do it in php. For me it is important to change passport key when I reinstalled my Laravel App. For Laravel key it works but for passport .... More: I have in laravel 10 thee command works in shell exec! But in php it can not recognized!

Thanks in advance

comannd

Artisan::call('passport:keys', ['--force' => true]);

Error

The command "passport:keys" does not exist.
1 like
3 replies
BMO-VIK's avatar

This usually happens when Laravel Passport is installed but its service provider for commands hasn't been registered or loaded correctly. Here’s a clear explanation and how you can solve it, especially since you're trying to call it from PHP, not shell.

Make sure the Service Provider is loaded, Passport is installed correctly...

Other troubleshoots might be... If the passport:keys command isn't recognized inside Artisan::call(), it might be because commands are only registered in console environment.

php artisan vendor:publish --tag=passport-migrations php artisan migrate php artisan vendor:publish --tag=passport-config

If this does not fix the problem please provide the error.

1 like
stackprogramer's avatar
Level 1

@BMO-VIK After some reading about register console command I did it,now it works. Thanks very much.

Registering Commands

<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Laravel\Passport\Console\KeysCommand;
use Laravel\Passport\Console\ClientCommand;
class Kernel extends ConsoleKernel
{
  /**
   * The Artisan commands provided by your application.
   *
   * @var array
   */
  protected $commands = [
    //
    // Explicitly register Passport’s keys command
    KeysCommand::class,
    ClientCommand::class,
    ];

...

}


Using commands in controller

    Artisan::call('passport:keys', ['--force' => true]);
    // Personal access
    Artisan::call('passport:client', [
        '--personal' => true,
        '--name'     => 'Web Personal Access Client',
    ]);
BMO-VIK's avatar

Hey, Sorry for my late response! Sounds good! Happy you found out :)

Please or to participate in this conversation.