diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index f86340ded9..09106f4c9a 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -216,8 +216,22 @@ class Preferences { $fullName = sprintf('preference%s%s', $user->id, $name); Cache::forget($fullName); + /** @var Preference $pref */ $pref = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data', 'updated_at', 'created_at']); + if (null !== $pref && null === $value) { + try { + $pref->delete(); + } catch (Exception $e) { + Log::error(sprintf('Could not delete preference: %s', $e->getMessage())); + } + + return new Preference; + } + if (null === $value) { + return new Preference; + } + if (null !== $pref) { $pref->data = $value; $pref->save();