自定义模型和领域与Sentinel / Laravel [英] Custom Model and fields with Sentinel / Laravel
问题描述
所以,我的User表没有默认字段名称。
所有的名字都是西班牙语,所以Sentinel在寻找correo时寻找电子邮件。
另外,执行
Sentinel :: check(),
我收到此消息错误:
SQLSTATE [42S22]:未找到列:1054未知列'管理员在where子句(SQL:select * from`administrador`,`administrador`.`id` = 1和`administrador```deleted_at`为空限制1)
其实id不存在,PK被称为administradorid
我发现只有一个资源是非常快的:
https://github.com/cartalyst/sentinel/wiki/Extending-Sentinel
它说这是极端mly easy,但不要提这种情况。
所以,基本上,如何自定义Sentinel Model的所有字段名称???
这是我的模型:
class Administrador extends EloquentUser {
保护$ table ='administrador';
protected $ fillable = [];
protected $ guarded = ['administradorid'];
protected $ hidden = ['contrasena','remember_token'];
使用SoftDeletes;
protected $ dates = ['deleted_at'];
}
任何帮助将不胜感激!
首先, id
问题是一个基本的Laravel雄辩问题。如果您的模型的主键不是 id
,则需要将模型上的 $ primaryKey
属性设置为正确的字段名称。此外,如果您的主键不是自动增量整数,那么您需要将 $ incrementing
属性设置为 false
对于电子邮件
问题,这是一个Sentinel的具体问题。 EloquentUser
类有一个 $ loginNames
属性,设置为包含用户登录的有效字段名称数组。默认值为 ['email']
,因此您需要覆盖此属性并将其更改为字段名称。
所以,您的管理员
类最终看起来像:
Administrador类扩展了EloquentUser {
使用SoftDeletes;
protected $ table ='administrador';
protected $ primaryKey ='administradorid';
// public $ incrementing = false; //只有当主键不是一个autoinc int
protected $ fillable = [];
protected $ guarded = ['administradorid'];
protected $ hidden = ['contrasena','remember_token'];
protected $ dates = ['deleted_at'];
// Sentinel覆盖
//保存登录名字段的数组
protected $ loginNames = ['correo'];
}
I', integrating a new system to an existing database.
So, my User table doesn't have default fields names.
All names are in spanish, so, Sentinel looks for email when he should look for "correo"
Also, when executing
Sentinel::check(),
I get this message error:
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)
In fact, id doesn't exists, the PK is called administradorid
The only resource I found is a very quick one:
https://github.com/cartalyst/sentinel/wiki/Extending-Sentinel
It says it is extremly easy, but do not mention this case.
So, basically, how can I customize all the fields name of the Sentinel Model???
Here is my model:
class Administrador extends EloquentUser {
protected $table = 'administrador';
protected $fillable = [];
protected $guarded = ['administradorid'];
protected $hidden = ['contrasena', 'remember_token'];
use SoftDeletes;
protected $dates = ['deleted_at'];
}
Any help will be appreciated!
First, the id
issue is a basic Laravel Eloquent issue. If the primary key for your model is not id
, then you need to set the $primaryKey
property on your model to the correct field name. Additionally, if your primary key is not an autoincrementing integer, then you need to set the $incrementing
property to false
, as well.
For the email
issue, that is a Sentinel specific issue. The EloquentUser
class has a $loginNames
property that is set to an array of valid field names that contain user logins. The default is just ['email']
, so you need to override this property and change it to your field name.
So, your Administrador
class ends up looking like:
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'];
}
这篇关于自定义模型和领域与Sentinel / Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!