$attributes */ public function get($model, string $key, $value, array $attributes): ?ArrayObject { if (isset($attributes[$key])) { try { $decrypted = Crypt::decryptString($attributes[$key]); } catch (\Illuminate\Contracts\Encryption\DecryptException $e) { Log::warning('Failed to decrypt array object', ['key' => $key, 'error' => $e->getMessage()]); return null; } $decoded = json_decode($decrypted, true); if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) { Log::warning('Failed to decode encrypted array', ['key' => $key, 'error' => json_last_error_msg()]); return null; } return new ArrayObject($decoded ?? []); } return null; } /** * Prepare the given value for storage. * * @param \Illuminate\Database\Eloquent\Model $model * @param mixed $value * @param array $attributes * @return array|null */ public function set($model, string $key, $value, array $attributes): ?array { if (! is_null($value)) { $encoded = json_encode($value); if ($encoded === false) { throw new \RuntimeException( "Failed to encode value for encryption [{$key}]: ".json_last_error_msg() ); } $encrypted = Crypt::encryptString($encoded); return [$key => $encrypted]; } return null; } }