tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.29k stars 1.54k forks source link

Error after installing in version 5.4 #975

Open alaksandarjesus opened 7 years ago

alaksandarjesus commented 7 years ago

I am getting this error after composer update.... I am using laravel version 5.4.*

Call to undefined method Illuminate\Foundation\Application::share()

My providers array

`'providers' => [App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
         'Tymon\JWTAuth\Providers\JWTAuthServiceProvider'

    ],`

My alias array


 'aliases' => ['View' => Illuminate\Support\Facades\View::class,
        'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth',
        'JWTFactory' => 'Tymon\JWTAuth\Facades\JWTFactory'

    ],

My composer.json , "tymon/jwt-auth": "0.5.*"

The error is

C:\wamp\www\myproject\app>php artisan vendor:publish --provider="Tymon\JW
TAuth\Providers\JWTAuthServiceProvider"
PHP Fatal error:  Call to undefined method Illuminate\Foundation\Application::sh
are() in C:\wamp\www\myproject\app\vendor\tymon\jwt-auth\src\Providers\JW
TAuthServiceProvider.php on line 122
spirant commented 7 years ago

I get the same error when updating to Laravel 5.4. I will delay upgrading to the latest version for now and thank everyone in advance for any work getting a fix for this ;-)

 1/1 FatalThrowableError in JWTAuthServiceProvider.php line 122: Call to undefined method Illuminate\Foundation\Application::share()

    in JWTAuthServiceProvider.php line 122
    at JWTAuthServiceProvider->registerUserProvider() in JWTAuthServiceProvider.php line 100
    at JWTAuthServiceProvider->register() in Application.php line 568
    at Application->register(object(JWTAuthServiceProvider)) in ProviderRepository.php line 74
    at ProviderRepository->load(array('Illuminate\\Auth\\AuthServiceProvider', 'Illuminate\\Broadcasting\\BroadcastServiceProvider', 'Illuminate\\Bus\\BusServiceProvider', 'Illuminate\\Cache\\CacheServiceProvider', 'Illuminate\\Foundation\\Providers\\ConsoleSupportServiceProvider', 'Illuminate\\Cookie\\CookieServiceProvider', 'Illuminate\\Database\\DatabaseServiceProvider', 'Illuminate\\Encryption\\EncryptionServiceProvider', 'Illuminate\\Filesystem\\FilesystemServiceProvider', 'Illuminate\\Foundation\\Providers\\FoundationServiceProvider', 'Illuminate\\Hashing\\HashServiceProvider', 'Illuminate\\Mail\\MailServiceProvider', 'Illuminate\\Notifications\\NotificationServiceProvider', 'Illuminate\\Pagination\\PaginationServiceProvider', 'Illuminate\\Pipeline\\PipelineServiceProvider', 'Illuminate\\Queue\\QueueServiceProvider', 'Illuminate\\Redis\\RedisServiceProvider', 'Illuminate\\Auth\\Passwords\\PasswordResetServiceProvider', 'Illuminate\\Session\\SessionServiceProvider', 'Laravel\\Tinker\\TinkerServiceProvider', 'Illuminate\\Translation\\TranslationServiceProvider', 'Illuminate\\Validation\\ValidationServiceProvider', 'Illuminate\\View\\ViewServiceProvider', 'App\\Providers\\AppServiceProvider', 'App\\Providers\\AuthServiceProvider', 'App\\Providers\\BroadcastServiceProvider', 'App\\Providers\\EventServiceProvider', 'App\\Providers\\RouteServiceProvider', 'Tymon\\JWTAuth\\Providers\\JWTAuthServiceProvider', 'Mpociot\\ApiDoc\\ApiDocGeneratorServiceProvider')) in Application.php line 543
    at Application->registerConfiguredProviders() in RegisterProviders.php line 17
    at RegisterProviders->bootstrap(object(Application)) in Application.php line 208
    at Application->bootstrapWith(array('Illuminate\\Foundation\\Bootstrap\\LoadEnvironmentVariables', 'Illuminate\\Foundation\\Bootstrap\\LoadConfiguration', 'Illuminate\\Foundation\\Bootstrap\\HandleExceptions', 'Illuminate\\Foundation\\Bootstrap\\RegisterFacades', 'Illuminate\\Foundation\\Bootstrap\\RegisterProviders', 'Illuminate\\Foundation\\Bootstrap\\BootProviders')) in Kernel.php line 160
    at Kernel->bootstrap() in Kernel.php line 144
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
    at Kernel->handle(object(Request)) in index.php line 53
jerguslejko commented 7 years ago

Same here.

juanpscotto commented 7 years ago

jwt it's not 100% compatible with laravel 5.4 yet see https://github.com/tymondesigns/jwt-auth/pull/969

cabrerabywaters-zz commented 7 years ago

+1. It would be great If you could tag the develop branch that seems to have the fix for 5.4 =) Thanks youuu!!!

spirant commented 7 years ago

Looking at another project relying on the share method https://github.com/mpociot/laravel-apidoc-generator/pull/150/files this may be the approach:

// Change this in JWTAuthServiceProvider.php line 122:
$this->app['tymon.jwt.provider.user'] = $this->app->share(function ($app) {

// To this?
$this->app->singleton('tymon.jwt.provider.user', function ($app) {

There are further uses of share in this Class which would likely need updating too.

alexbowers commented 7 years ago

@spirant You should actually use singleton. It's part of the upgrade guides.

https://laravel.com/docs/5.4/upgrade search for share on there.

daniel-seitz commented 7 years ago

If not known yet. On release 1.0.0-beta.2 This doesn't seem to do anything, yet: php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"

nisevi commented 7 years ago

Installing "dev-master" solved the issue for me, since it was solved here.