相关疑难解决方法(0)

Laravel雄辩的mutators不适用于更新数据

我的模型访问器和变量有数据库表字段中的哈希/重新哈希数据。例如:

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时,数据将被更新:

在此处输入图片说明 为什么在更新信息时不以加密形式存储信息?

php laravel eloquent laravel-5.6

2
推荐指数
2
解决办法
1963
查看次数

标签 统计

eloquent ×1

laravel ×1

laravel-5.6 ×1

php ×1