我的模型访问器和变量有数据库表字段中的哈希/重新哈希数据。例如:
public function setFullNameAttribute($value)
{
$this->attributes['full_name'] = Helper::geted('encrypt', $value);
}
public function getFullNameAttribute($value)
{
return Helper::geted('decrypt', $value);
}
Run Code Online (Sandbox Code Playgroud)
当我将数据保存到数据库时,所有发送数据都以散列形式保存,但在更新数据上不散列。我的保存/更新代码:
$profile = [
'full_name' => "John",
'address' => "United Kingdom"
];
$profile_save = new Profile($profile);
$exist = Personal::where('user_id', Auth::id())->count();
if($exist == 0) $user->profile()->save($profile_save);
if($exist == 1) $user->profile()->update($profile);
Run Code Online (Sandbox Code Playgroud)
当我第一次将此信息保存到数据库时:
当我第二次输入当前URL时,数据将被更新: