Undefined type 'Tymon\JwTAuth\Contracts\JWTSubject'

Viewed 1964

I installed this package:

composer require tymon/jwt-auth  "^1.0"

Then ran:

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

And then:

 php artisan jwt:secret

I also added this to the app.php config file:

    Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

The commands ran without errors. However, following the documentation I'm trying to implement the JWTSubject interface on the User model. However like this:

use Tymon\JwTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject
{

The JWTSubject is underlined with red and it says:

Undefined type 'Tymon\JwTAuth\Contracts\JWTSubject'.

Do you know what can be the issue? Thanks

3 Answers

It worked with these commands, ignoring the platform requirements:

composer require tymon/jwt-auth --ignore-platform-reqs

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

php artisan jwt:secret

Your class is not loaded in autoload_classmap.php You should do composer dump-autoload.

I opened "vendor\tymon\jwt-auth\src\Contracts\JWTSubject.php" and that error suddenly fixed.

I don't know why, but it works

Related