diff --git a/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php b/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php index f4f97351f..f59e89d40 100644 --- a/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php +++ b/migrations/2018_01_30_222801_migrate_users_table_preferences_columns.php @@ -9,9 +9,7 @@ * file that was distributed with this source code. */ -use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Schema\Builder; -use Illuminate\Support\Arr; return [ 'up' => function (Builder $builder) { diff --git a/src/User/NotificationPreference.php b/src/User/NotificationPreference.php new file mode 100644 index 000000000..b1b1c6ad7 --- /dev/null +++ b/src/User/NotificationPreference.php @@ -0,0 +1,19 @@ +belongsTo(User::class); + } +} diff --git a/src/User/User.php b/src/User/User.php index 161db365f..538387df1 100644 --- a/src/User/User.php +++ b/src/User/User.php @@ -448,6 +448,11 @@ class User extends AbstractModel })->count(); } + public function notificationPreferences() + { + return $this->hasMany(NotificationPreference::class); + } + /** * Get the values of all registered preferences for this user, by * transforming their stored preferences and merging them with the defaults. @@ -461,7 +466,7 @@ class User extends AbstractModel return $value['default']; }, static::$preferences); - $user = Arr::only((array) json_decode($value, true), array_keys(static::$preferences)); + $user = Arr::only($this->notificationPreferences->toArray(), array_keys(static::$preferences)); return array_merge($defaults, $user); }