|null, array|null> */ class EncryptedArrayCast implements CastsAttributes { /** * @param array $attributes * @return array|null */ public function get(Model $model, string $key, mixed $value, array $attributes): ?array { if ($value === null || $value === '') { return null; } try { $value = Crypt::decryptString($value); } catch (DecryptException) { // Legacy plaintext JSON written before this column was encrypted. } $decoded = json_decode((string) $value, true); return is_array($decoded) ? $decoded : null; } /** * @param array $attributes */ public function set(Model $model, string $key, mixed $value, array $attributes): ?string { if ($value === null) { return null; } return Crypt::encryptString(json_encode($value, JSON_THROW_ON_ERROR)); } }