Laravel 5.6.26 Error- Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found

Add library to composer.json:

"require": {
    ...
    "tymon/jwt-auth": "1.0.0-beta.3"
    ...
 },

Run this command in console: composer update

Add provider in config/app.php:

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

Add aliases in the same file `config/app.php':

'aliases' => [
    ...
    'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
    'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
    ...
],

And then run command in console: php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider" next run:

php artisan jwt:secret

First of all, since you are using Laravel 5.6 you need to have this version (1.0.0-rc.2 as the newest stable version), then there is no need to implicitly type hint the service provider or the alias for its facade! the library itself shall do so for you. So please remove what you've added to $providers & $aliases arrays.

Then make sure to run:

composer dump-autoload -o

and

php artisan clear-compiled

If you are running less than 5.6 for Laravel, let me know


There is some problem while downloading the package Try running

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

and in your config/app.php make providers as

Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

Also provide the Aliases as:

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

After all the above steps publish your vendor:

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

And generate auth secret : php artisan jwt:secret

Tags:

Php

Laravel