1
votes

I'am new to laravel, and this is my first question because I could not find a solution anywhere. I implemented JWT-token somehow and it worked until I mess it up. Now when I type php artisan serve I get that error, or when I try to publish. I tried everything like in question --- Laravel 5.6.26 Error- Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found --- but it won't work. When I add in composer.json "tymon/jwt-auth": "^0.5.12" I get an error class LaravelServiceProvider not found, and when I change it to "tymon/jwt-auth": "^1.0.0-beta.3" or "tymon/jwt-auth": "^1.0.0-rc.2" then I ger error JWTAuthServiceProvider not found. I also tried composer require illuminate/auth but it won't work. Can I get some help please.

2

2 Answers

2
votes

I had this same issue and I solved it by executing these commands

composer require illuminate/auth

composer require tymon/jwt-auth:"^1.0.0-rc.2"

composer update

Then

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

You can safely remove from your app.php file

Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,

'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class
0
votes

You need to also add the alias to config/app.php like so:

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

'aliases' = [
....
//other aliases
...
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
'JWTFactory' => Tymon\JWTAuthFacades\JWTFactory::class`
]

and then include it at the top of the PHP file you want to use it in, like

use JWTAuth;