简体   繁体   中英

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.

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

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

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

跑:

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

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 .

After going through the output of

$composer update --no-scripts

my attention was on the below error

- 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].

So, illuminate/auth was the source of trouble.

$composer require illuminate/auth
$composer update

Fixed finally.

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

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

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"

You may not have JWT yet!

Execute:

composer require tymon/jwt-auth

Then:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM