Closed HarutEnoqyan closed 2 years ago
Getting LogicException: Choice question must have at least 1 choice available. ChoiceQuestion.php:36 error when running the php artisan passport:install command. Can you help with this please? steps:
- Creating new lumen project
- composer require dusterio/lumen-passport
- bootstrap/app.php configs
- php artisan migrate
- php artisan passport:install
Hello, did you find the answer?
Hello, did you find the answer?
Hi. Nope. I have used tymon/jwt-auth
I have the same problem
Had the same issue. Did a migrate:rollback on all new tables added by lumen-passport and ran php artisan migrate again. For some reason that fixed the error for me :)
please provide the solution
I am having the same problem.
Running composer require laravel/passport "8.4.4"
fixed the problem for me.
Running
composer require laravel/passport "8.4.4"
fixed the problem for me.
This worked for me. Thanks!
Running
composer require laravel/passport "8.4.4"
fixed the problem for me.
Worked for me too. I guess for now I can use this.
Hi, I already use composer require laravel/passport "8.4.4" but still get the error and couldn't fixed it. Please help me.
I got this error after trying to go back to "8.4.4"
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for laravel/passport 8.4.4 -> satisfiable by laravel/passport[v8.4.4].
- Conclusion: remove guzzlehttp/guzzle 7.0.1
- Conclusion: don't install guzzlehttp/guzzle 7.0.1
- laravel/passport v8.4.4 requires guzzlehttp/guzzle ^6.0 -> satisfiable by guzzlehttp/guzzle[6.0.0, 6.0.1, 6.0.2, 6.1.0, 6.1.1, 6.2.0, 6.2.1, 6.2.2, 6.2.3, 6.3.0, 6.3.1, 6.3.2, 6.3.3, 6.4.0, 6.4.1, 6.5.0, 6.5.1, 6.5.2, 6.5.3, 6.5.4, 6.5.5, 6.5.x-dev].
- Can only install one of: guzzlehttp/guzzle[6.0.0, 7.0.1].
- Can only install one of: guzzlehttp/guzzle[6.0.0, 7.0.1].
...
- Installation request for guzzlehttp/guzzle (locked at 7.0.1) -> satisfiable by guzzlehttp/guzzle[7.0.1].
Installation failed, reverting ./composer.json to its original content.
Seems like my phpoffice/phpspreadsheet requires guzzlehttp/guzzle ^7.0 while laravel/passport "8.4.4" requires guzzlehttp/guzzle: 6 so, i don't think downgrading to 8.4.4 is the fix to me
Now I just need to find out if "Choice question must have at least 1 choice available" will affect using passport since Password grant client is not created. I'm trying to move from JWT to Passport authentication.
EDIT: after some setup in bootstrap\app and config\app, i did php artisan migrate:fresh
and php artisan passport:install --force
, the error disappeared. I'm not sure what have I done.
Seems like my phpoffice/phpspreadsheet requires guzzlehttp/guzzle ^7.0 while laravel/passport "8.4.4" requires guzzlehttp/guzzle: 6 so, i don't think downgrading to 8.4.4 is the fix to me
Now I just need to find out if "Choice question must have at least 1 choice available" will affect using passport since Password grant client is not created. I'm trying to move from JWT to Passport authentication.
EDIT: after some setup in bootstrap\app and config\app, i did
php artisan migrate:fresh
andphp artisan passport:install --force
, the error disappeared. I'm not sure what have I done.
I try to use php artisan migrate: refresh and php artisan passport:install --force but still not work for me. Can you please share your setup on bootstrap\app and config\app, please?
this is what's added to bootstrap\app.php
$app->routeMiddleware([
'client.credentials' => Laravel\Passport\Http\Middleware\CheckClientCredentials::class,
]);
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
$app->configure('auth');
here is from config/auth.php (copy from vendor/laravel/lumen-framework/config/auth.php
'guards' => [
'api' => [
'driver' => 'passport',
'provider' => 'users'
],
],
---
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User_Master::class #state your user model
]
],
then I execute php artisan passport:client
Which user ID should the client be assigned to?: # i input my admin ID from user_master
1
What should we name the client?:
MyClient
Where should we redirect the request after authorization? # blank
I don't know which step fixed the problem. but after creating passport:client
, i migrate:fresh
, and the error is gone, with --force
or not
Encryption keys generated successfully.
Personal access client created successfully.
Client ID: 1
Client secret: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
<----------- normally the code died beyond this point and show "Choice question must have at least 1 choice available"
Password grant client created successfully.
Client ID: 2
Client secret: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
this is what's added to bootstrap\app.php
$app->routeMiddleware([ 'client.credentials' => Laravel\Passport\Http\Middleware\CheckClientCredentials::class, ]); $app->register(Laravel\Passport\PassportServiceProvider::class); $app->register(Dusterio\LumenPassport\PassportServiceProvider::class); $app->configure('auth');
here is from config/auth.php (copy from vendor/laravel/lumen-framework/config/auth.php
'guards' => [ 'api' => [ 'driver' => 'passport', 'provider' => 'users' ], ], --- 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User_Master::class #state your user model ] ], this is what's added to bootstrap\app.php
$app->routeMiddleware([ 'client.credentials' => Laravel\Passport\Http\Middleware\CheckClientCredentials::class, ]); $app->register(Laravel\Passport\PassportServiceProvider::class); $app->register(Dusterio\LumenPassport\PassportServiceProvider::class); $app->configure('auth');
here is from config/auth.php (copy from vendor/laravel/lumen-framework/config/auth.php
'guards' => [ 'api' => [ 'driver' => 'passport', 'provider' => 'users' ], ],
'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User_Master::class #state your user model ] ],
then I execute `php artisan passport:client`
Which user ID should the client be assigned to?: # i input my admin ID from user_master 1 What should we name the client?: MyClient Where should we redirect the request after authorization? # blank
**I don't know which step fixed the problem**. but after creating `passport:client`, i `migrate:fresh`, and the error is gone, with `--force `or not
Encryption keys generated successfully. Personal access client created successfully. Client ID: 1 Client secret: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX <----------- normally the code died beyond this point and show "Choice question must have at least 1 choice available" Password grant client created successfully. Client ID: 2 Client secret: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This is works! I follow your code and did the same like you. It save my time. Thank you.
@rik72c Hey thanks a lot this worked for me!
@rik72c Adding the providers to config/auth.php fixed the issue! Great job, thanks!
I just want to add the fact that, I did exactly same setup as what was shown in the official readme of dusterio/lumen-passport, the config file set up and the bootstrap/app.php set up.
The one thing that helped in overcoming this ChoiceQuestion.php line 36 problem was the following.
php artisan migrate:fresh php artisan passport:install --force
Make sure you backup your database because a fresh migration will delete all tables including your data.
You need to create a config file for auth services as config/auth.php
:
<?php
return [
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
'guards' => [
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\User::class
]
]
];
And after register this on bootstrap/app.php
:
$app->configure('auth');
If you are using Lumen 7+, insert this on bootstrap/app.php
also:
$app = new \Dusterio\LumenPassport\Lumen7Application(
dirname(__DIR__)
);
So, refresh the database and run passport:install
again
php artisan migrate:fresh
php artisan passport:install
This worked for me :wink:
Do not forget to install the default Laravel Passport and then install the Lumen passport
composer require laravel/passport
composer require dusterio/lumen-passport
Make sure the bootstrap/app.php file has the following,
<?php
require_once __DIR__ . '/../vendor/autoload.php';
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
dirname(__DIR__)
);
$app->withFacades();
$app->withEloquent();
/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
/*
|--------------------------------------------------------------------------
| Register Config Files
|--------------------------------------------------------------------------
|
| Now we will register the "app" configuration file. If the file exists in
| your configuration directory it will be loaded; otherwise, we'll load
| the default version. You may register other files below as needed.
|
*/
$app->configure('app');
/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/
// $app->middleware([
// App\Http\Middleware\ExampleMiddleware::class
// ]);
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
]);
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
// register two service providers - original one and Lumen adapter
$app->register(Laravel\Passport\PassportServiceProvider::class);
$app->register(Dusterio\LumenPassport\PassportServiceProvider::class);
// load the auth configuration files since Lumen doesn't load config files automatically
$app->configure('auth');
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
$app->router->group([
'namespace' => 'App\Http\Controllers',
], function ($router) {
require __DIR__ . '/../routes/web.php';
});
// set the oauth route for the lumen passport
\Dusterio\LumenPassport\LumenPassport::routes($app, ['prefix' => 'v1/oauth']);
return $app;
Also, set up the auth configuration in config/auth.php (create if not available)
<?php
return [
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
'guards' => [
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\User::class
]
]
];
Finally, run the migration and install passport
php artisan migrate:fresh
php artisan passport:install --force
You need to create a config file for auth services as
config/auth.php
:<?php return [ 'defaults' => [ 'guard' => 'api', 'passwords' => 'users', ], 'guards' => [ 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], ], 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => \App\User::class ] ] ];
And after register this on
bootstrap/app.php
:$app->configure('auth');
If you are using Lumen 7+, insert this on
bootstrap/app.php
also:$app = new \Dusterio\LumenPassport\Lumen7Application( dirname(__DIR__) );
So, refresh the database and run
passport:install
againphp artisan migrate:fresh php artisan passport:install
This worked for me 😉
This one fix everything, and everything back to normal. 👍
The problem because when you create fresh installation lumen, there are no config folder (with auth.php) by default.
in config /auth.php is the main problem un comment that u it will not show any error
<?php
return [ 'defaults' => [ 'guard' => 'api', 'passwords' => 'users', ],
'guards' => [
'api' => [
'driver' => 'passport',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\User::class
]
]
]; / return [ 'defaults' => [ 'guard' => env('AUTH_GUARD', 'api'), ], 'guards' => [ 'api' => ['driver' => 'api'], 'myguard' => ['driver' => 'mydriver'], ], ]; /
Hi, I already use composer require laravel/passport "8.4.4" but still get the error and couldn't fixed it. Please help me.
composer require laravel/passport "8.4.4"
if you've ever tried that but doesn't work, use the
--update-with-dependencies
option. this worked for me
@mateus4k worked for me on Laravel 8
you need to set up your provider in you /config/auth.php file if you dont have any providers it can create the grant token
'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User_Master::class #state your user model ] ],
When I added the user provider, the error was gone!
just enable the eloquent, that fixed my problem
Did anyone find a fix to this?
You need to create a config file for auth services as
config/auth.php
:<?php return [ 'defaults' => [ 'guard' => 'api', 'passwords' => 'users', ], 'guards' => [ 'api' => [ 'driver' => 'passport', 'provider' => 'users', ], ], 'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => \App\User::class ] ] ];
And after register this on
bootstrap/app.php
:$app->configure('auth');
If you are using Lumen 7+, insert this on
bootstrap/app.php
also:$app = new \Dusterio\LumenPassport\Lumen7Application( dirname(__DIR__) );
So, refresh the database and run
passport:install
againphp artisan migrate:fresh php artisan passport:install
This worked for me 😉
you are a genious!
Getting LogicException: Choice question must have at least 1 choice available. ChoiceQuestion.php:36 error when running the php artisan passport:install command. Can you help with this please? steps: