"message": "Method Illuminate\\Auth\\RequestGuard::fromUser does not exist.", "status_code": 500?

"message": "Method Illuminate\\Auth\\RequestGuard::fromUser does not exist.",
    "status_code": 500

配置代码

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    |
    | This option controls the default authentication "guard" and password
    | reset options for your application. You may change these defaults
    | as required, but they're a perfect start for most applications.
    |
    */

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    |
    | Next, you may define every authentication guard for your application.
    | Of course, a great default configuration has been defined for you
    | here which uses session storage and the Eloquent user provider.
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | Supported: "session", "token"
    |
    */

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Resetting Passwords
    |--------------------------------------------------------------------------
    |
    | You may specify multiple password reset configurations if you have more
    | than one user table or model in the application and you want to have
    | separate password reset settings based on the specific user types.
    |
    | The expire time is the number of minutes that the reset token should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

出现问题的代码

\Auth::guard('api')->fromUser($user)
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 7
liyu001989

多提供一点信息,代码,完整的报错,贴一下你 config/auth.php 的代码。你也可以对比一下项目的源码

5年前 评论

@liyu001989
首先非常感谢您能回答我的问题
配置文件如下 已经检查过了 和源码文件是一样的
是在调用 \Auth::guard('api')->fromUser($user) 出现的问题 上面已经补充了配置 和 错误问题

5年前 评论
liyu001989

file

5年前 评论

@liyu001989
我这个使用的是 Passport 认证
如果修改成 jwt 是否就没法使用 Passport 认证了?
修改成 jwt 之后 postman 报错 Syntax error
我用的 laravel 5.6 版本 在调用 \Auth::guard('api')->fromUser($user) 出现的问题 提示的是应该未找到 fromUser 方法

5年前 评论
liyu001989

file

5年前 评论

@liyu001989 您好 再咨询您 一个问题 生成 token 后 如果token 泄露 如果再拿到接口 地址 就会出现 数据泄露 请问 这个种情况 一般如何解决? 例如通常的vue 单页应用 只要拿到 用户token 就可以 免登陆操作 这样会不会很危险?

5年前 评论
liyu001989

任何一种 token 泄露了情况都一样,你的问题就是我的银行卡密码泄露了,如果在拿到我的银行卡,那么怎么办。

  1. 怎么泄露的,没用 https?
  2. 服务器判断不了你是个正常的 token 还是被泄露的 token,怎么办?记录每次用户请求到的 token,给用户展示个列表?用户可以选择注销某个 token?
5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!