【发布时间】:2018-01-19 11:34:53
【问题描述】:
我有员工表,无论用户使用模型输入如何,我都想将 fname 和 lname 列保存为驼峰式大小写。我正在使用 ardent 进行验证,还有其他方法吗?我使用了像波纹管这样的变异器,但仍然将其保存为普通外壳。我做错什么了?
protected $fillable = [
'fname','lname'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $table = 'employees';
protected $guarded = array('id', 'password');
public static $rules = array(
'fname' => 'required',
'lname' => 'required'
);
/**
* Make sure that first name is capitalized BEFORE saving it to the database
*
* @param $value
* @return string
*/
public function setFnameAttribute($value)
{
$this->attributes['fname'] = ucfirst($value);
}
/**
* Make sure that last name is capitalized BEFORE saving it to the database
*
* @param $value
* @return string
*/
public function setLnameAttribute($value)
{
$this->attributes['lname'] = ucfirst($value);
}
【问题讨论】: