'boolean', 'cc' => 'array', 'bcc' => 'array', 'mail_enabled' => NotificationEnabledStatus::class, 'in_app_enabled' => NotificationEnabledStatus::class, ]; public function preferences() { return $this->hasMany(NotificationPreference::class); } public function isEmailUserControllable() { return in_array($this->mail_enabled, [NotificationEnabledStatus::ChoiceOn, NotificationEnabledStatus::ChoiceOff]); } public function isInAppUserControllable() { return in_array($this->in_app_enabled, [NotificationEnabledStatus::ChoiceOn, NotificationEnabledStatus::ChoiceOff]); } // Check if user has enabled this notification for email public function isEnabledForPreference(?NotificationPreference $preference = null, $type = 'mail') { $type = $type === 'app' ? 'in_app_enabled' : 'mail_enabled'; if ($this->{$type} === NotificationEnabledStatus::Force) { return true; } if ($this->{$type} === NotificationEnabledStatus::Never) { return false; } if ($preference) { return $preference->{$type}; } // Return true if choice_on, false if choice_off return $this->{$type} === NotificationEnabledStatus::ChoiceOn; } }