【问题标题】:Call to undefined method App\Models\StudentModel::createToken()调用未定义的方法 App\Models\StudentModel::createToken()
【发布时间】:2021-04-15 15:07:22
【问题描述】:

This is my Models code.Here,StudentModel 是我的自定义模型,它扩展了 Authenticable。但我收到此错误 App\Models\StudentModel::createToken()

This is the providers

And this is the controller part where i'm getting error

【问题讨论】:

    标签: laravel authentication laravel-passport


    【解决方案1】:

    自定义user模型后,需要修改auth配置。

    config/auth.php 中,您更改以下代码。

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

    【讨论】:

    • 因此,您应该更详细地分享您的信息。请!您可以更新您的帖子。
    • 你修改config/auth.php后是否运行php artisan config:clear
    • 问题已更新。没有没有运行该命令。
    【解决方案2】:

    您需要 use 您在用户模型中导入的 HasApiTokens 特征:

    class StudentModel extends Authenticatable 
    {
        use HasFactory, Notifiable, HasApiTokens;
        //...
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-21
      • 1970-01-01
      • 2022-12-09
      • 2021-10-22
      • 1970-01-01
      • 2023-02-06
      • 2021-03-19
      • 2021-06-24
      • 1970-01-01
      相关资源
      最近更新 更多