This commit is contained in:
James Cole 2019-02-03 18:25:58 +01:00
parent 1fc2c998de
commit 25b2b43a38

View File

@ -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();