I have applied the passport auth in laravel. I have done this on my local machine and AWS server too. Now I am trying to apply the same to a shared hosting, where I won't be able to access the terminal. So my curiosity is just to know is it possible to apply for the passport without php artisan passport: install
?
Try to make a controller with a connected HTTP route, and put
Artisan::call('passport:install');
there. Then go to the url to run the command.
Put the command in your composer.json post install script:
"post-install-cmd": [
"php artisan passport:install"
]
There are many different events you can hook into other than post install as well. Composer events
Usually you would use the following code in your controller to excute an Artisan call:
Artisan::call('passport:install');
However, this doesn't work on passport:install and you will get the error:
There are no commands defined in the "passport" namespace
To fix this you must add the following code to boot method at AppServiceProvider.php :
<?php
namespace App\Providers;
use Laravel\Passport\Console\ClientCommand;
use Laravel\Passport\Console\InstallCommand;
use Laravel\Passport\Console\KeysCommand;
use Laravel\Passport\Passport;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
Passport::routes();
/*ADD THIS LINES*/
$this->commands([
InstallCommand::class,
ClientCommand::class,
KeysCommand::class,
]);
}
This code works with no error
shell_exec('php ../artisan passport:install');