使用 Sentinel 的自定义模型和字段 / Laravel

Custom Model and fields with Sentinel / Laravel

I',将新系统集成到现有数据库中。

因此,我的用户 table 没有默认字段名称。

所有名字都是西班牙语,因此,Sentinel 在他应该查找 "correo"

的时候查找电子邮件

此外,当执行

Sentinel::check(), 

我收到此消息错误:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'administrador.id' in 'where clause' (SQL: select * from `administrador` where `administrador`.`id` = 1 and `administrador`.`deleted_at` is null limit 1)

其实id是不存在的,PK叫administradorid

我找到的唯一资源是一个非常快速的资源:

https://github.com/cartalyst/sentinel/wiki/Extending-Sentinel

上面写着非常简单,但是这个案例就别提了

那么,基本上,我如何自定义 Sentinel 模型的所有字段名称???

这是我的模型:

class Administrador extends EloquentUser {

protected $table = 'administrador';
protected $fillable = [];
protected $guarded = ['administradorid'];
protected $hidden = ['contrasena', 'remember_token'];
use SoftDeletes;

protected $dates = ['deleted_at'];

}

任何帮助将不胜感激!

首先,id问题是一个基本的LaravelEloquent问题。如果您的模型的主键不是 id,那么您需要将模型上的 $primaryKey 属性 设置为正确的字段名称。此外,如果您的主键不是自动递增整数,那么您还需要将 $incrementing 属性 设置为 false

对于 email 问题,这是一个特定于 Sentinel 的问题。 EloquentUser class 有一个 $loginNames 属性 设置为包含用户登录的有效字段名称数组。默认值只是 ['email'],因此您需要覆盖此 属性 并将其更改为您的字段名称。

因此,您的 Administrador class 最终看起来像:

class Administrador extends EloquentUser {
    use SoftDeletes;

    protected $table = 'administrador';
    protected $primaryKey = 'administradorid';
    //public $incrementing = false; // only if primary key is not an autoinc int

    protected $fillable = [];
    protected $guarded = ['administradorid'];
    protected $hidden = ['contrasena', 'remember_token'];
    protected $dates = ['deleted_at'];

    // Sentinel overrides

    // array of fields that hold login names
    protected $loginNames = ['correo'];
}