Ozzdev
Ozzdev

Reputation: 65

Undefined type 'Tymon\JwTAuth\Contracts\JWTSubject'

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

Upvotes: 2

Views: 6569

Answers (4)

Fer D R
Fer D R

Reputation: 1

It's the PHP Intelephense extension in VS Code, I uninstalled it and that was the error. I had already had problems with this extension before

Upvotes: 0

Alex
Alex

Reputation: 497

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

Upvotes: 1

Shabiq Ghazi Arkaan
Shabiq Ghazi Arkaan

Reputation: 11

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

I don't know why, but it works

Upvotes: 0

Ozzdev
Ozzdev

Reputation: 65

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

Upvotes: 1

Related Questions