【问题标题】:SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'where clause' (SQL: select * from `customer` where `` = 1 limit 1)SQLSTATE [42S22]:未找到列:1054 'where 子句'中的未知列''(SQL:select * from `customer` where ``= 1 limit 1)
【发布时间】:2019-12-25 11:37:41
【问题描述】:

我已更改 Laravel 5.8 项目的身份验证表。

但是当我尝试登录时,我收到以下错误:

SQLSTATE[42S22]:未找到列:1054 'where 子句'中的未知列''(SQL:select * from customer where ``= 1 limit 1)

这就是我的 auth.php 的样子:

'providers' => [
    'users' => [
        'driver' => 'eloquent',
        'model' => \App\Models\Sop\Customer::class
    ]
]

客户模型类:

class Customer extends Model implements Authenticatable
{
protected $table = "customer";
protected $primaryKey = 'customer_id';
protected $connection = "sop";
protected $fillable = [
    'customer_ref',
    'customer_status_id',
    'registration_level',
    'email_address',
    'username',
    'password',
    'verification_code'
];

public function getAuthIdentifier()
{
    return $this->customer_id;
}

public function getAuthPassword()
{
    return $this->password;
}

public function getRememberToken()
{
    if (!empty($this->getRememberTokenName())) {
        return $this->{$this->getRememberTokenName()};
    }
}

public function setRememberToken($value)
{
    if (!empty($this->getRememberTokenName())) {
        $this->{$this->getRememberTokenName()} = $value;
    }
}

public function getRememberTokenName()
{
    return $this->remember_token;
}

/**
 * Get the name of the unique identifier for the user.
 *
 * @return string
 */
public function getAuthIdentifierName()
{
    return $this->customer_id;
}
}

但是,当尝试上传时,调用此行时会出错:

Auth::check()

如果我错过了应该在问题中添加的任何内容,请提出,我会更新问题。

【问题讨论】:

    标签: php mysql laravel laravel-5 eloquent


    【解决方案1】:

    这个函数 getAuthIdentifierName 应该返回列名,而不是我返回实际值。

    所以它应该看起来像:

    public function getAuthIdentifierName()
    {
        return 'customer_id';
    }
    

    【讨论】:

    • 经过几天的谷歌搜索没有任何成功。最后你救了我的命。谢谢!!!
    猜你喜欢
    • 2015-06-03
    • 2019-09-12
    • 1970-01-01
    • 2020-03-01
    • 2020-06-08
    • 1970-01-01
    • 2021-03-29
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多