9

I am using Laravel 5.4 and JWT Auth Library for user authentication in API development. After installation while i am running php artisan jwt:generate then it throws me error of

Method Tymon\JWTAuth\Commands\JWTGenerateCommand::handle() does not exist 

Any idea what i am missing ?

Chintan7027
  • 7,115
  • 8
  • 36
  • 50

8 Answers8

25

This error generally display when you install jwt package in laravel 5.5 version. then after you set service providers and run following command.

php artisan jwt:generate

then you seen this error message in terminal.

how to resolve it? simple follow this step

Step - 1 Re-install package

composer require tymon/jwt-auth:dev-develop --prefer-source

or the following is a new release package use laravel 6.X

composer require tymon/jwt-auth:1.0.*

in this developement version this errors fixed.

Step - 2 Set Service Provider

'providers' => [
    ....
    Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class to 
    Tymon\JWTAuth\Providers\LaravelServiceProvider::class
],

Step - 3 Generate key

php artisan jwt:secret

i found this solution from here https://laravelcode.com/post/method-tymonjwtauthcommandsjwtgeneratecommandhandle-does-not-exist

Harsukh Makwana
  • 4,296
  • 3
  • 27
  • 34
  • 1
    Currently first step should be "composer require tymon/jwt-auth:1.0.*" and then proceed with second and third step – Uros Nov 15 '19 at 12:05
5

Go to JWTGenerateCommand.php file located in vendor/tymon/src/Commands and paste this method

public function handle() { $this->fire(); }
Toni
  • 670
  • 11
  • 29
3

It's never a great idea to change anything in the vendor folder but the there's two ways to deal with this ...

  1. Generate a random string yourself and just change the value in the JWT config file.

  2. Go to Tymon\JWTAuth\Commands\JWTGenerateCommand and change the fire method to handle.

3

go to given file path

vendor/tymon/jwt-auth/src/Commands/JWTGenerateCommand.php

change function name

public function fire() to public function handle()

run command:

php artisan jwt:generate

abhishek kumar
  • 448
  • 4
  • 10
1

I'm publishing this answer because I have crash in this error more than one time.

The only solution I found that it works with Laravel 5.6 is the following:

  • Add "tymon/jwt-auth": "1.0.0-rc.1" to composer.json and run composer update
  • Open config/app.php and add the following:

config/app.php:

 'providers' => [
   /*
   * JWT Service Provider...
   */
   Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
 ],
 'aliases' => [
   'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
   'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
 ],
  • Execute:

    php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"

  • Finally, execute: php artisan jwt:secret

After all that, when I hit my endpoint for login I got the following exception:

Class Tymon\JWTAuth\Providers\JWT\NamshiAdapter does not exist

This was fixed by:

  • Open config/jwt.php and change the following:

config/jwt.php:

'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class,
'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class,

Finally, note that in order to work your User model should be defined as follows:

class User extends Authenticatable implements JWTSubject
{
     ...
     public function getJWTIdentifier()
    {
        return $this->getKey();
    }
    public function getJWTCustomClaims()
    {
        return [];
    }
    ...
}
Christos Papoulas
  • 2,469
  • 3
  • 27
  • 43
0

I can advise one solution. Go to JWTGenerateCommand.php file located in vendor/tymon/src/Commands and paste this part of code public function handle() { $this->fire(); }

I know this is not an elegant solution, but it works. I hope this might help until official fix arrive.

see here for more info

Shankar
  • 2,890
  • 3
  • 25
  • 40
0

Change fire() function to handle() in this path vendor/tymon/jwt-auth/src/commands/JWTGenerateCommand.php

Zia
  • 506
  • 3
  • 20
-2

In the file path: /vendor/tymon/jwt-auth/src/Commands/JWTGenerateCommand.php

Add public function

public function handle()
{
    $this->fire();
}
rene
  • 41,474
  • 78
  • 114
  • 152
Gaurav Pandey
  • 67
  • 1
  • 2