在我的模型中,这个字段address
是加密的.我用casts
加密
protected $casts = ['address' => 'encrypted'];
我try 在模型上创建访问器
public function getAddressAttribute($value)
{
try {
$decryptedValue = Crypt::decryptString($value);
} catch (\Illuminate\Contracts\Encryption\DecryptException $e) {
$decryptedValue = ""; //or null
}
return $decryptedValue;
}
但当我try 访问它时,它将返回为空/空,具体取决于我输入的内容
"email": "flangosh@example.com",
"name": "Kim Schulist",
"address": "",
我的方法有什么问题吗?
另外,当我删除TRY CATCH语句或不使用访问器时,我得到的结果是
"message": "The MAC is invalid.",
个