【问题标题】:BadMethodCallException - Call to undefined method Illuminate\Database\Query\Builder::getAuthIdentifierName()BadMethodCallException - 调用未定义的方法 Illuminate\Database\Query\Builder::getAuthIdentifierName()
【发布时间】:2017-07-08 14:03:26
【问题描述】:

我已经安装了 Laravel 5.4 并使用了 php artisan make:auth。一切都很好,我设置了我的数据库并迁移了所有内容。我还测试了登录和注册,它运行良好。

之后,我设法设置了我的其他控制器和模型。在我测试了一个控制器之后(基本上,我将图像存储在数据库中,然后显示它)。它工作得很好,我存储了图像然后显示它。

但是,从那时起,当我尝试登录或注册时收到错误消息。

当我尝试访问 http://localhost:8000/loginhttp://localhost:8000/register 时,我收到以下错误:

调用未定义的方法 Illuminate\Database\Query\Builder::getAuthIdentifierName()

对于这个我不完全确定我应该分享我的代码的哪一部分,但这是我的 Modal User.php:

namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

use App\User;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */


    protected $table = 'users';

    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

提前谢谢你们,如果您需要我的代码的其他部分,我很乐意分享。

【问题讨论】:

  • 分享你的路由和控制器文件

标签: php mysql laravel-5


【解决方案1】:

首先首先运行 php artisan migrate 确保您的数据库中有一个表

User.php // 用户模型添加主键来摆脱这个错误

 protected $primaryKey = 'yourPrimaryKey';

【讨论】:

    猜你喜欢
    • 2019-12-12
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    相关资源
    最近更新 更多