【问题标题】:ReflectionException: Class Tymon\JWTAuth\Http\Middleware\Authenticate does not exist in fileReflectionException:文件中不存在类 Tymon\JWTAuth\Http\Middleware\Authenticate
【发布时间】:2018-11-18 04:02:22
【问题描述】:

我正在尝试使用令牌(在邮递员中)获取用户详细信息。但我收到错误:

ReflectionException: Class Tymon\JWTAuth\Http\Middleware\Authenticate does not exist in file C:\xampp\htdocs\sistema\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 779

我的应用\Http\Kernel.php

protected $routeMiddleware= [
    ...
    'auth.jwt' => \Tymon\JWTAuth\Http\Middleware\Authenticate::class,
    ...
];

我的配置\app.php

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

我的项目github:https://github.com/vika0/project

【问题讨论】:

  • 嗨 vika,注释已导入 jwauth(app.php 和内核)的行,然后执行 composer require tymon/jwt-auth。我在这里放了一个将这些插件安装到 laravel 中的教程(jwt-auth.readthedocs.io/en/docs/laravel-installation)
  • 我做了这些步骤,现在我出错了:ReflectionException: Class auth.jwt does not exist in file
  • 使用已注释的依赖项进行作曲家安装(就像我的第一条评论)
  • 我做了composer require tymon/jwt-auth。现在我又做了一次,得到:Nothing to install or update
  • 好的,让我们看看我们这样做更容易,把项目的 composer.json 放在答案中,然后我想为什么你的项目不能使用你的代码

标签: php laravel jwt


【解决方案1】:

我修改了我放在后面的另一个文件:

您需要这样做,因为此错误已在开发分支中修复但在主分支中未修复,因此请更改插件。

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

app/Http/Kernel.php(替换你那里的那个)

    'auth.jwt' => \Tymon\JWTAuth\Http\Middleware\Authenticate::class

配置/jwt.php

  'jwt' => 'Tymon\JWTAuth\Providers\JWT\Namshi',

    /*
    |--------------------------------------------------------------------------
    | Authentication Provider
    |--------------------------------------------------------------------------
    |
    | Specify the provider that is used to authenticate users.
    |
    */

    'auth' => 'Tymon\JWTAuth\Providers\Auth\Illuminate',

    /*
    |--------------------------------------------------------------------------
    | Storage Provider
    |--------------------------------------------------------------------------
    |
    | Specify the provider that is used to store tokens in the blacklist
    |
    */

    'storage' => 'Tymon\JWTAuth\Providers\Storage\Illuminate',

配置/app.php

'providers' => [
        /*
         * Laravel Framework Service Providers...
         */
        Illuminate\Auth\AuthServiceProvider::class,
        Illuminate\Broadcasting\BroadcastServiceProvider::class,
        Illuminate\Bus\BusServiceProvider::class,
        Illuminate\Cache\CacheServiceProvider::class,
        Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
        Illuminate\Cookie\CookieServiceProvider::class,
        Illuminate\Database\DatabaseServiceProvider::class,
        Illuminate\Encryption\EncryptionServiceProvider::class,
        Illuminate\Filesystem\FilesystemServiceProvider::class,
        Illuminate\Foundation\Providers\FoundationServiceProvider::class,
        Illuminate\Hashing\HashServiceProvider::class,
        Illuminate\Mail\MailServiceProvider::class,
        Illuminate\Notifications\NotificationServiceProvider::class,
        Illuminate\Pagination\PaginationServiceProvider::class,
        Illuminate\Pipeline\PipelineServiceProvider::class,
        Illuminate\Queue\QueueServiceProvider::class,
        Illuminate\Redis\RedisServiceProvider::class,
        Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
        Illuminate\Session\SessionServiceProvider::class,
        Illuminate\Translation\TranslationServiceProvider::class,
        Illuminate\Validation\ValidationServiceProvider::class,
        Illuminate\View\ViewServiceProvider::class,
        //Remove both lines because for me worked without them
        //Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class,
        /*
         * Package Service Providers...
         */
        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
    ],

在 storage/framework 内部,您需要创建各种文件夹,分别是 storage/framework/sessions 和 storage/framework/views

毕竟需要执行这个命令:

php artisan jwt:secret

[已编辑]

我现在看到了这个屏幕:

我希望这是你想要的

【讨论】:

猜你喜欢
  • 2017-03-31
  • 2016-05-30
  • 2018-12-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-02
  • 1970-01-01
  • 2017-12-04
  • 1970-01-01
相关资源
最近更新 更多