Gowtham
Gowtham

Reputation: 351

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

FYI,

I have gone through several web links and found solutions like changing/adding to composer.json file

"tymon/jwt-auth": "^0.5.12" 
"tymon/jwt-auth": "^1.0.0-beta.3" 
"tymon/jwt-auth": "^1.0.0-rc.2"

app.php config file with LaravelServiceProvider/JWTAuthServiceProvider

providers => [
---
        Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

        Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,
---
]
aliases => [
-----
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
-----
]

And

composer update --no-scripts
composer update

When publishing:

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

Error message below.

In ProviderRepository.php line 208:

  Class 'Tymon\JWTAuth\Providers\LaravelServiceProvider' not found

composer update output below

$composer update

Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove laravel/framework v5.6.26
    - Conclusion: don't install laravel/framework v5.6.26
    - Installation request for tymon/jwt-auth 1.0.0-beta.3 -> satisfiable by tymon/jwt-auth[1.0.0-beta.3].
    - Conclusion: don't install laravel/framework v5.6.1
    - Conclusion: don't install laravel/framework v5.6.0
    - tymon/jwt-auth 1.0.0-beta.3 requires illuminate/auth 5.1.* || 5.2.* || 5.3.* || 5.4.* -> satisfiable by illuminate/auth[5.1.x-dev].

    - Installation request for laravel/framework 5.6.* -> satisfiable by laravel/framework[5.6.x-dev].

Thanks in advance.

Upvotes: 12

Views: 29266

Answers (9)

user15349180
user15349180

Reputation: 11

You may not have JWT yet!

Execute:

composer require tymon/jwt-auth

Then:

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

Upvotes: 0

Athar Marfatia
Athar Marfatia

Reputation: 13

Try this line of code, I hope this is helpful:

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

To publish the configuration file in Laravel, you need to run following line of code :

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

Upvotes: 0

Harendra Singh
Harendra Singh

Reputation: 323

changed Class 'Tymon\JWTAuth\Providers\JWTAuthServiceProvider' to Tymon\JWTAuth\Providers\LaravelServiceProvider::class

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

Upvotes: 0

J.D. Sandifer
J.D. Sandifer

Reputation: 906

I had a similar error after upgrading to Laravel 6 and jwt-auth 1.0. I had finished the upgrade on my local machine and gotten everything working by following the installation instructions for jwt-auth 1.0 (and ignoring the part for Laravel 5.4 and below).

The error came when I tried to deploy to my test environment. composer install and php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider" both failed with the error Class 'Tymon\JWTAuth\Providers\JWTAuthServiceProvider' not found (that's the old provider from jwt-auth 0.5).

The key for me was to delete this file: .../bootstrap/cache/config.php.

Apparently, this file can also be an issue, but it wasn't present for me: .../bootstrap/cache/services.php.

Upvotes: 1

Divyesh pal
Divyesh pal

Reputation: 947

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

Upvotes: 14

Amir Hedieh
Amir Hedieh

Reputation: 1178

i've had this problem for a while and none these answers worked for me. after struggling with problem i found a solution.

try installing jwt-auth from command below if you use laravel above 5.5 :

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

then you will have no problem anymore

Upvotes: 7

tommie
tommie

Reputation: 21

Run:

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

Upvotes: 2

Mohamed Mo Kawsara
Mohamed Mo Kawsara

Reputation: 4688

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

Upvotes: 7

Sachin Ingale
Sachin Ingale

Reputation: 96

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

Upvotes: 8

Related Questions